Make apk with Capitalized package name in android studio

痴心易碎 提交于 2019-12-22 17:36:53

问题


Before we start let me explain the assumptions:

  1. I realize it is bad convention to have capitalized package names. In my situation, we are dealing with an 3rd party published android app with capitalized package name, unfortunately app has millions download so republishing is not an option.

  2. I have done extensive research and cannot find solution, the closest SO questions are this and this and this.

The problem :

App was originally developed with eclipse, which can create signed app that has capitalized package name. App must be moved to AS now, which refuses to generate signed apk with capitalized package name. See error below:

Here are relevant parts of my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="TESTING.CAPITALIZED"

...

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

<activity
        android:name="TESTING.CAPITALIZED.Activity_xxx"
...

Please note I have tried changing manifest activity tagged naming convention to: (but same error)

<activity
        android:name=".Activity_xxx"
...

The question:

We need a method/hack in Android Studio to get past this. I don't care how or if it involves magic such as editing dlls, need generate signed apk in AS.

Additional Findings: It appears that in Android Studio, as long as the 1st letter in the package is lower case, we can compile and generate apk. For example, in my example if I refactor my project to zTESTING.CAPITALIZED, I can successfully generate apk. However this doesn't fix my problem because my client's package name is all caps.


回答1:


I found solution for INSTALL_PARSE_FAILED_MANIFEST_MALFORMED The difference between the eclipse and android studio project just in AndroidManifest.xml

in Eclipse path to activity:

<activity android:name="WinActivity">

in Android Studio :

<activity android:name="Com.my.package.WinActivity">

And problem with capital letter in AS only in path to all Activityes in AndroidManifest; Because Android Studio always merge manifest file, and fill full path to all Activityes;

If you get compiled apk from AS, open it it apktools, change AndroidManifest.xml (change path to <activity android:name="WinActivity">) and make apk with apktools back. All will work.

Second way to fix this problem: Move all java files into another package with lowercase letter. for example some.new.package. Package with capital letter will stay empty. In AndroidManifest.xml - you need to set full path to all Activityes.

<activity android:name="some.new.package.WinActivity">`

Package in manifest you stay old;

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="Com.my.package"

and in build.gradle you stay old package to:

applicationId "Com.my.package"

If you see and error with R class in your classes. Just import Com.my.package.R in all class when need it.




回答2:


If anyone is looking for an answer, this issue has been resolved in Android Studio 3.0 RC1. Refer to google issue tracker and update if you face any issues https://issuetracker.google.com/issues/64595077



来源:https://stackoverflow.com/questions/45604183/make-apk-with-capitalized-package-name-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!