Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming the Package Name inside an APK

I have created an AIR app that is currently on the market. To update the app, obviously I must keep the same package name. My first version's were packaged using Eclipse with the ADT plugin.

Now to use AIR 3.0 Native Extensions (ANE) which were not available when I first developed the app, I currently must create my APK using AIR's command line tools. Unfortunately, these command line tools force you to have a package name that starts with the word "air". For example, I need the package name "com.example". AIR creates the package name as "air.com.example".

So now, I cannot update my app in the market since the package name has changed. Adobe has this horrific article to help you rename and remove the "air" in the package. I'm not a great programmer so this has really stumped me. http://kb2.adobe.com/cps/875/cpsid_87562.html

Apparently this info is out of date or incorrect in a few areas. I have completely stumbled at step 12 which uses apkbuilder:

 apkbuilder final.apk -u -z resources.arsc -f classes.dex

I am getting this error message:

THIS TOOL IS DEPRECATED. See --help for more information. java.io.FileNotFoundException: resources.arsc does not exist

I have used step 10 to create the new resources.arsc file. It clearly DOES exist and in the correct location. I tried using apkbuilder with other resources.arsc files taken from other projects. I still get the same error message.

Is there a chance in hell of this working? If anyone is interested in this, I have a zip file with a sample AIR apk, windows bat files for all the command line work, and all the needed utilities so they don't need to be downloaded. To get started you just need to change my path.bat to fit your system. And you need notepad++ (or an equivalent) to batch automate renaming the package name across several files. bradwallacedesign.com/dktimer/renameApkProject.zip

Thanks so much!

like image 236
brad51 Avatar asked Feb 09 '12 20:02

brad51


People also ask

Can we change package name of apk?

I would recommend unpacking the apk with apktool, and then edit the apktool. yml, setting renameManifestPackage to the new package name. Then when you rebuild the apk with apktool, it should use aapt's --rename-manifest-package functionality to change the package name.

How do I change the name of an apk file?

Navigate to the folder in which your apk is present. In that folder select your APK file. Right-click on it and click on rename option to rename your APK file.


1 Answers

this was done on a pc. i have no idea how to do this on a mac.

i don't recommend using this to remove the "air." from an air package name. If you do so, the user will not be prompted to download air on their device. the user will get an error message instead with no clue to the problem. of course you can use air captive runtime to solve this issue.

http://bradwallacedesign.com/share/renameAPK.zip

download and unzip my file (renameAPK.zip) to c:\renameAPK.

required files:

  1. my file (renameAPK.zip) which contains the apkTool
  2. java jdk/jre
  3. android SDK
  4. notepad++ (or an equivalent text editor that can rename across multiple files)

i made many bat files since i'm not sure how to combine them into one file. you will need to edit each one to change your path names and file names to work with your computer and your apk file.

i numbered all the bats in the order that i use them. once a command line is open, i type the number of the bat file i want then hit the tab key to automatically finish the name of the bat file then hit enter to run that bat file.

instructions:

double click `openCmd.bat to open a command line pointing to the directory with all your files.

0. run 0path.bat to set your path. (i can't remember now if the adobe air sdk is needed for this but i have it in my path. obviously, the JDK is needed and the android sdk for the jarsigner and zip align i think.)

1. run 1decompileAPK.bat to have apkTool decompile your app into a folder called UNZIPPEDapk

2. follow the instructions in 2editManifest & PackageName - Instructions (not a bat).txt to edit the manifest and package name using Notepad++ inside UNZIPPEDapk:

edit AndroidManifest.xml:

a. change package name from air.oldPackageName to newPackageName

b. edit other needed entries:

c. rename folder system inside "smali" folder so that it works with your new package name for example: if the old package name was: air/oldName then change the folders to match the new package name: air/newName

use notepad++ (or any editor that can find and replace text over many files)


d. ctrl+shift+f --- "Find in files"

  find:
air/oldPackageName
  replace with:
newPackageName
  where:
all files in UNZIPPEDapk/smali

(i think there were over 200 replacements)

3. run 3buildDistFolder.bat to have apkTool build the new apk in the UNZIPPEDapk\Dist folder

4. follow the instructions in 4getMissingFiles - instructions.txt to reinstate the 2 missing files in the new build:

a. Two files were not built during 3buildDistFolder:

3buildDistFolder.bat built the new apk in the \UNZIPPEDapk\dist folder but it failed to copy 2 files:

(skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF

\AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.classpath') (skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF \AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.project')

grab these 2 files from your original apk and drop them into your new apk in the correct folder

b. copy yourApp.apk from DKTimer/Dist/ to root directory where your bat files are.

5. run 5signAPK.bat to sign the apk.

developer.android.com/guide/publishing/app-signing.html

6. run 6verifySigned.bat to verify the signing worked properly

7. run 7zipAlign.bat to align the apk file.

developer.android.com/guide/developing/tools/zipalign.html


You are finished at this point. Continue on if you want to test it on a device.

8. run 8installAPK.bat to install the apk on a usb connected device.

9. run 9remoteDebugger.bat if you want to use remote debugging.


i hope this helps someone. let me know if i forgot to include something. also, if you know a better way to do this, please comment (such as how to combine this into 1 long pausing bat file...)

like image 183
brad51 Avatar answered Oct 26 '22 10:10

brad51