Android: Element Activity is now allowed here - android

In the code below Android Studio shows me
"Element activity is now allowed here"
when I hover over activity tag, and the app doesn't launch the activity which is the default one, I tried clean project, rebuild project then restarted Android Studio, I tried invalidate cashes / restart, and the problem still exist, how to fix this?
<activit
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activit>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.blabla.testapp1"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}

In your manifest i see you wrote activit instead of activity. Make it okey
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Related

AndroidManifest.xml "Unresolved package" Error

I am developing a Media Player app. I was implementing MediaButtonReceiver (which is used to control Media inputs given from Headphone, bluetooth like external devices).
But while declaring receiver in the manifest file I encountered a number of errors.
Errors:
Unresolved package session
Unresolved class MediaButtonReceiver
Class referenced in the manifest, com.example.android.MediaPlaybackService, was not found in the project or the libraries
Unresolved package android
Unresolved class MediaPlaybackService
build.gradle:app
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.helloworld"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HelloWorld">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="android.support.v4.media.session.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
<service android:name="com.example.android.MediaPlaybackService" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</service>
</application>
</manifest>
"Unresolved package/reference" means that the supporting library doesn't exist. According to the bewildering Android dev doc, you must download it by adding the following code to Gradle Scripts > build.gradle (Module: xxx.app) inside dependencies{}, resync and the error will disappear from androidx.media.session.MediaButtonReceiver
implementation("androidx.media:media:1.6.0")
and add this code for the error to disappear from android.support.v4.media.session.MediaButtonReceiver
implementation("com.android.support:support-media-compat:28.0.0")
Check latest version of androidx and v4
Maybe try to declare it in AndroidManifest.xml like the documentation said (for AndroidX) :
<receiver android:name="androidx.media.session.MediaButtonReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>

My manifest went missing after failing building gradle with Glide Library

I tried using the Glide library in order to load a profile picture from Facebook, in the gradle I implemented the 4.8.0 version (which is not the latest) and it made this error :
ERROR: Failed to parse XML in C:\Users\Paul Jouet\Desktop\ESILV\S5\Mobile Programming\ProjetTest2\app\src\main\AndroidManifest.xml
ParseError at [row,col]:[18,89]
Message: expected start or end tag
Affected Modules: app
My manifest module has disappeared, it is still in my project and I can open it, but not from the 'android' section... When I tried syncing again without the implementation, the error remains, I tried some solutions I found like cleaning the project and rebuild it, but none worked.
This is how the 'android' section looks like after the failed syncing, the module 'manifest' is missing even though it is still in the same location as before
Can someone explain to me how this can happen ? It makes no sense to me since I obviously deleted the part causing the problem... The only solution I could find is to recreate a project from scratch and copy paste all my code, but this is not viable since it can happen again.
Thank you for helping !
Edit : here are my manifest and gradle codes
Gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.projettest2"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.facebook.android:facebook-android-sdk:4.42.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
}
}
Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projettest2">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:authorities="com.facebook.app.FacebookContentProvider464643414180175" //I changed the ID
android:name="com.facebook.FacebookContentProvider"
android:exported="false" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
</manifest>

Error: "Version code not found in manifest."

I am trying to build the signed app bundle, so publishing. All I did was update the OS versions and some graphics. The app runs on the ADKs just fine.
When building the signed apk, I get this error message:
"Version code not found in manifest."
This is the error log:
"Caused by: com.android.ide.common.workers.WorkerExecutorException:
1 exception was raised by workers:
com.android.tools.build.bundletool.exceptions.manifest.ManifestVersionException$VersionCodeMissingException:
Version code not found in manifest."
Thanks for anyone that can help me sort this small issue out. I searched on here and could not find a good fix.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sevillasoundservices.warningshot">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShotgunSensing"
android:label="#string/title_activity_shotgun"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RifleSensing"
android:label="#string/title_activity_rifle"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PistolSensing"
android:label="#string/title_activity_pistol"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.sevillasoundservices.warningshot"
minSdkVersion 24
targetSdkVersion 28
versionName '1.0.2'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13-beta-3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
I am hoping someone here can tell me what is missing. I expect to simply insert some code on the manifest file to sort this out, however, all other examples of other coders manifests do not have any version showing anywhere.
Add the versionCode to your gradle. Something like below...
defaultConfig {
applicationId "com.sevillasoundservices.warningshot"
minSdkVersion 24
targetSdkVersion 28
versionName '1.0.2'
versionCode 3
}
The versionCode is an incremental integer that is used to determine which version is higher than the other. I think this is only enforced on signed APKs, that's why you haven't seen the error earlier.
More info can be found in Android Developer Guides
You need to add versionCode code as follows.
android {
compileSdkVersion 32
defaultConfig {
minSdkVersion 28
targetSdkVersion 32
versionCode 4
versionName '0.0.4.'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
For me, Error was in my build.gradle that I was trying to generate VersionCode dynamically. For that I need to add a method that generated versionCode. It had no issue till I tried to generate a release. But got the error when I tried creating signed bundle.
def getVersionCode() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
android {
compileSdkVersion 32
defaultConfig {
minSdkVersion 28
targetSdkVersion 32
versionCode getVersionCode()
versionName '0.0.4.'
}
The reason was my method name getVersionCode() conflicted with the default getter for field versionCode and was hiding it.
If you want dynamic generation like the above your method name has to be something other than getVersionCode(), may be generatetVersionCode()

App doesn't show up in Laucher List and can't be opened

I made an app, that worked just fine until yesterday.
Somehow I broke it that it doesn't show up in the Launcher's App list. I only can uninstall through the Apps tab in the Settings.
As I have already made a Beta on Play Store I tried to open it there, but there only shows up the "Uninstall" button.
I think it has to do something with the Manifest or build.gradle.
So here they are:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.mrminemeet.reviewcheck">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"></activity>
</application>
</manifest>
And here the build.gradle (Module: App):
apply plugin: 'com.android.application'
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
signingConfigs {
}
compileSdkVersion 27
defaultConfig {
applicationId "at.mrminemeet.reviewcheck"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName '0.1'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:gridlayout-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.google.android.gms:play-services-ads:12.0.0'
}
If you need other files just comment on them.
If you want to use multiple category then you need to create another intent-filter
like this
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Link to document
https://developer.android.com/guide/components/intents-filters.html#ExampleFilters

ActionBar is not being displayed anymore after migration from Eclipse to Android Studio

I recently tried to edit my 4 year old android application in the recently appeared Android Studio 2.3.1.
After importing the code I can launch it on my mobile phone. However the action bar seems to have disappeared. What has gone wrong?
How can I tell android to display the action bar?
I have implemented the action bar activity like this:
public class MainActivity extends ActionBarActivity
My build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "de.my.app"
minSdkVersion 8
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
I also tried to replace the compile command with something newer one:
compile 'com.android.support:appcompat-v7:25.3.1'
but already the syncing in android studio fails like this, throwing the following error:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library [com.android.support:appcompat-v7:25.3.1] /home/user/.android/build-cache/815cafa5312f1d889eb1134b2184a62b3f88d8a3/output/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage
I haven't done much android coding in the last 4 years so I assume the ActionBar stuff has changed profoundly but shouldn't there be a way to compile the old code as it is using android studio?
Edit:
This is the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.myApp.myAppDemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/icon_app"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="de.myApp.myAppDemo.Splash"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light">
<intent-filter>
<action android:name="de.myApp.myAppDemo.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.PropertiesAssign"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="de.myApp.myAppDemo.PROPERTIESASSIGN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.PropertiesView"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="de.myApp.myAppDemo.PROPERTIESVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Meanwhile I got at least the ActionBar to be displayed. However I had to increase the MinSDK and targetSdkVersion / compileSdkVersion bigly: From 8,17 to 15,23. Moreover I had to look in the SDK-Manager to see which exact version of Android Support Library was installed on my system (23.2.0) and adapt the corresponding line in build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23 //->modified
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "de.Geo.geodraw"
minSdkVersion 15 //->modified
targetSdkVersion 23 //->modified
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:23.2.0" //->modified
}
Not sure whether it was relevant or necessary but following this page I also added
allprojects {
repositories {
jcenter()
maven { //->modified
url "https://maven.google.com" //->modified
} //->modified
}
}
in another build.gradle file.
If there is another solution without drastically changing minSdk and targetSdk I will accept that answer.

Categories

Resources