Installation failed with message "INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME" - android

So I was doing some refactoring of package names in my project and now i'm no longer able to install my app. Right around the same time that I updated to the most current version of android studio. I believe that may be the problem because I think i did the refactoring before the upgrade, I just don't remember 100%
Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dodgingfire" >
<application
android:allowBackup="true"
android:icon="#mipmap/dodging_fire_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".gamemain.GameMainActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is how I have my packages organized
http://prntscr.com/gcrw99
This is the full error message when I try to run my app
Installation failed with message Failed to finalize session : INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: Invalid manifest package: must have at least one '.' separator.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.
WARNING: Uninstalling will remove the application data!
Do you want to uninstall the existing application?
Even when I accept to delete the existing application, It still gives me an error and doesn't install my app let alone run it.

The package name in your source manifest file is not actually the one that ends up in the APK being installed. During manifest merging process, the final package name is based on the applicationId value in your app's build.gradle file.
As the error message says, you need at least one . in the package name.
Other reasons for INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME can be found in PackageParser#validateName() source.

Related

Android Studio expands Activity name in AndroidManifest.xml

I upgraded my project from Eclipse to Android Studio.
Everything is working, including different flavors (in Eclipse I had an ANT script that auto-generated the sourcecode for the different flavors).
I can also generate the different signed APK's. And these all work on the device.
Also uploading these APK's to GooglePlay is no problem.
User also get these updates, but after the update they need to re-create the shortcut to the app on the home screen. The old shortcut is removed.
I believe this is due to the fact that "Android Studio" modifies stuff in the AndroidManifest.xml when generating the APK.
In Eclipse source, in Android studio source and when I inspect the Eclipse generated APK I have the following (with the name being .StartUpActivity) :
<activity android:name=".StartUpActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
However, when I look into the generated apk from Android Studio this is modified to :
<activity android:name="be.abc.android.StartUpActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So the name has been changed from .StartUpActivity to be.abc.android.StartUpActivity.
In the end, this is the same path but I believe the shortcut just looks at the name .StartUpActivity, and decides it is no longer available and removes the shortcut....
Can I fix this in someway that the shortcuts don't get deleted. Or that Android Studio doesn't mess with the shortened package names in the AndroidManifest.xml ?
Indeed, as soon as you modify the launcher manifest entry, the shortcut has to be recreated. To avoid such issue, you can make use of activity-alias. A step-by-step guide can be found here.

Why is Android Studio 3.0.0 setting FLAG_TEST_ONLY on APKs?

I have arrived at Android Studio 3.0.0 (from the stable channel) via 3.0.0-rcX (from the Canary channel).
When I start a brand new app and build it, the following code (inside the app) shows that the FLAG_TEST_ONLY flag is set.
Log.e(TAG, "ApplicationInfo: " + (getApplicationInfo().flags & ApplicationInfo.FLAG_TEST_ONLY));
10-31 09:54:05.226 16129-16129/com.example.dummy E/MainActivity: ApplicationInfo: 256
The app's manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dummy">
<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>
</application>
</manifest>
The flag stops Device Policy Controllers from being able to install it: Upgrading app in background using Device Policy Controller
Why is this flag set, and how to I stop it from being set?
I ran headlong into this the other day. Based on my testing, this flag is added only if you run the app from Android Studio. Unfortunately, the APK filename doesn't hint at the problem. And, despite the documentation, this APK is only usable from Android Studio — I specifically was trying to install it via adb, which is supposed to work, but doesn't.
If you build the APK in other ways, the flag should not be added. Specifically, I used the assembleRelease Gradle task. I would expect the "Build APK(s)" menu option in Android Studio to work as well.
Given Instant Run and other potential shenanigans that Android Studio might be doing for direct-run builds versus other ones, I am not surprised that they added this flag. Personally, I would love a clearer option to opt out of all such shenanigans (and perhaps this flag), as I'm one of those weirdos who wants the app that I run from the IDE to be the same app that my users run.
FWIW, I have more background on this at this blog post.

Tag manifest attribute package has invalid character '_' even after removing said character

I am working in Android 2.3.3, and have run into this error: "Tag manifest attribute package has invalid character'_'. Initially, I was getting this error because my package name contained an underscore (com.isco_pipe.www.fieldtechapp). I have since renamed the package and removed the underscore (as you can see in the manifest file below). But the error persists upon an attempt to rebuild. Any thoughts?
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iscopipe.www.fieldtechapp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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="com.iscopipe.www.fieldtechapp.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Note: I previously asked a question about not being able to debug my app on my device (running Android Studio on a virtual machine). I am now attempting to setup and run my app in Android Studio directly on my Windows laptop to see if I can run the app on an emulator and debug from there. Unable to attach debugger to Android process in Android Studio 2.3.3
Check your build.gradle file also, what you gave in applicationId.
Make sure that you are editing the proper file. Android Studio has the absolutely aggravating "feature" where certain errors cause a file in build/ to pop up in the editor. In your case, it would be a merged manifest, not your actual manifest. Editing files in build/ will have no effect, as they get re-created on each build. So, make sure that you have modified your actual manifest (e.g., src/main/AndroidManifest.xml).

Why are two permissions always requested during installation?

I'm building a tiny dummy app using the command line (no gradle) with just a single blank activity, no permissions, no support libraries (or any other libraries, Google Play, etc) and yet Android always prompts for these two permissions during installation:
I understand how and why permissions get merged in when other libraries are included during a build, but my app has nothing included. I've extracted and decoded the compiled AndroidManifest.xml from the resulting APK and there's no <uses-permission> tag anywhere inside it.
According to this question, the READ_PHONE_STATE is added if no minSdkVersion value is entered, but I have one declared in the manifest (which I can also see in the compiled manifest).
Here is the source manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dummy.testapp"
versionCode="1">
<uses-sdk minSdkVersion="20" targetSdkVersion="22" />
<application
android:label="TestApp No Perms"
android:icon="#drawable/ic_launcher">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The single activity (MainActivity) just calls setContentView() on a blank layout.
Can anyone shed any light as to why these permissions are always requested or how to prevent them from being prompted for?
The answer came down to the missing android: prefix on the minSdkVersion and targetSdkVersion attributes.
Having no android: prefix doesn't cause any warnings or errors to be emitted from the resource compiler, but because of the missing prefix, the value is ignored when the APK manifest is parsed during installation.
The end result is that Android believes there is no minSdkVersion set and, as reported in Why does my app has the READ_PHONE_STATE permission although it's not declared in manifest?, automagically prompts for the permissions.
Adding in the android: prefix fixed the issue and allows the app to be installed with no permission prompts.

Android "No content provider found for permission revoke"

I have a simple app HelloWorld Android app in Eclipse (Mac OS X), when I install to the emulator/AVD the app shows up in "Settings->[Devices] Apps" but not in the launcher. I notice in logcat that I get these errors
W/ActivityManager( 160): No content provider found for permission revoke: file:///data/local/tmp/HelloWorld.apk
W/ActivityManager( 160): No content provider found for permission revoke: file:///data/local/tmp/HelloWorld.apk
I/PackageManager( 160): Running dexopt on: com.example.helloworld
D/dalvikvm( 870): DexOpt: load 124ms, verify+opt 459ms, 720236 bytes
I/ActivityManager( 160): Force stopping package com.example.helloworld uid=10044
I have set read/write/execute permissions on the .android directory.
In my case I forgot to define main activity. So, I add the following code inside AndroidManifest.xml main activity.
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
That was the result for Activity definition:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="RssfeedActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="DetailActivity"></activity>
</application>
I think that the problem is with the install directory permissions. /data/local needs to have write and execute rights to others in order for adb packages to install correctly.
Source
Try this, too: Android - Download App
I just found solution to Linux, but I not found for Windows, maybe because in Windows the directories and permissions were confused.
It's work for me: Add the user "Everyone" in folder "C://YourUser//.Android//" with full control, then restart the emulador.
I had the same problem on all of my devices. My problem was from the run configuration, I didn't checked the "launch default Activity".
I ran into this problem building a new signed APK.
I checked the V2(Full APK signature). Installing the APK on a device did not work anymore.
My solution was to check the V1 (Jar signature) instead. This did work.
https://stackoverflow.com/a/8646393/375929 - they say it's about /data/local permissions.
And here: Change /data/local Permissions is how to fix this.
My Solution was to remove the android:sharedUserId-Tag in the AndroidManifest.xml...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app"
android:theme="#style/MyAppTheme"
android:versionCode="9"
android:versionName="1.2.5" android:sharedUserId="mc">
Working on Cordova and emulator,
For me the problem was that the apk size was large and AVD RAM was too small,
problem happen when install new version of the apk and it failed with the message "No content provider found for permission revoke"
any one of those fixed the problem for me:
uninstall the old apk manually before install the new version
decrease the apk size
increase the device RAM
This works for me
Check your manifest application, if it contains this line
tools:replace="android:icon"
<application
android:name=".activities.MyApplication"
android:allowBackup="true"
android:icon="#drawable/launcher_icon"
android:label="#string/app_name"
android:largeHeap="true"
tools:replace="android:icon">
make it like this by remove this line
tools:replace="android:icon"
<application
android:name=".activities.MyApplication"
android:allowBackup="true"
android:icon="#drawable/launcher_icon"
android:label="#string/app_name"
android:largeHeap="true"
>

Categories

Resources