Rename package name inside APK

I created an AIR application that is currently on the market. To update the application, I must leave the same package name. My first version was packaged using Eclipse with the ADT plugin.

Now, in order to use the AIR 3.0 Source Extensions (ANE) that were not available when you first created the application, I currently need to create the APK using the AIR 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 can’t update my application on the market, because the package name has changed. Adobe has this terrible article that will help you rename and remove the "air" in the package. I'm not a great programmer, so it puzzled me a lot. http://kb2.adobe.com/cps/875/cpsid_87562.html

This information appears to be outdated or incorrect in several areas. I completely stumbled upon step 12, which uses apkbuilder :

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

I get this error message:

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

I used step 10 to create a new resources.arsc file. It obviously exists and is in the right place. I tried using apkbuilder with other resources.arsc files taken from other projects. I still get the same error message.

Is there any chance of this working? If someone is interested in this, I have a zip file with a sample AIR apk, windows bat files for the entire command line and all the necessary utilities so that they do not need to be downloaded. To get started, you just need to change your path.bat to fit your system. And you need notepad ++ (or equivalent) to batch automate the renaming of the package name in multiple files. bradwallacedesign.com/dktimer/renameApkProject.zip

Many thanks!

+6
source share
4 answers

This was done on a PC. I do not know how to do this on a Mac.

I do not recommend using this to remove β€œair”. from the name of the air bag. If you do this, the user will not be prompted to load air onto his device. the user will receive an error message without indicating a problem. Of course, you can use the runtime in the air to solve this problem.

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

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

required files:

  • my file (renameAPK.zip) which contains apkTool
  • java jdk / jre
  • Android SDK
  • notepad ++ (or an equivalent text editor that can rename multiple files)

I have made many bat files since I am not sure how to merge them into a single file. you will need to edit each to change the path names and file names to work with your computer and your apk file.

i numbered all the bits in the order in which I use them. after opening the command line, I type the number of the bat file that I want, then press the tab key to automatically end the name of the bat file, and then press Enter to launch this 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 specify the path. (I can't remember now if I need adobe air sdk for this, but I have it in my way. Obviously, JDK is needed, and Android sdk for jarsigner and zip align I think.)

1. run 1decompileAPK.bat so that apkTool decompiles your application into a folder called UNZIPPEDapk

2. Follow the instructions in 2editManifest and PackageName - Instructions (not 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 necessary entries:

c. rename the folder system inside the "smali" folder to work with your new package name, for example: if the old package name is: air / oldName, then change the folders according to the new package name: air / newName

use notepad ++ (or any editor that can find and replace text across 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 more than 200 replacements)

3. run 3buildDistFolder.bat so that apkTool collects a new apk in the UNZIPPEDapk \ Dist folder

4. Follow the instructions in 4getMissingFiles - instructions.txt to recover 2 missing files in the new assembly:

a. Two files were not created during 3buildDistFolder:

3buildDistFolder.bat built a new apk in the \ UNZIPPEDapk \ dist folder, but could not copy 2 files:

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

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

grab these 2 files from your original apk and put them in a new apk in the correct folder

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

5. run 5signAPK.bat to sign apk.

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

6. run 6verifySigned.bat to verify that the signature works

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

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


You are done at this point. Continue if you want to test it on the device.

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

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


Hope this helps someone. let me know if I forgot to turn something on. also, if you know the best way to do this, comment (for example, how to combine this into one long file with a pause) ...

+9
source

There is a simple environment variable with which you can easily disable the air. prefix air. . The following code exists in the Adobe AIR package:

 String optOut = System.getenv("AIR_NOANDROIDFLAIR"); if ((optOut == null) || (optOut.indexOf("true") == -1)) { packageName = "air." + packageName; } 

So, just set the AIR_NOANDROIDFLAIR environment AIR_NOANDROIDFLAIR to true , repackaging your application and there will be no air. prefix air. . Google how to set environment variables in windows or mac for your specific OS version.

For example, I use the command line compiler on Mac / Linux, so I run:

 > export AIR_NOANDROIDFLAIR=true > java -jar $AIR_HOME/lib/adt.jar -package -target apk-captive-runtime -storetype pkcs12 -keystore cert.p12 -storepass *** Main.apk Main-app.xml Main.swf 

Warning: I do not know what consequences this has. For some, the note above, this might just be a good idea with an inoperative runtime (but this default value comes from AIR 3.8).

Update: Renaun Erickson said this should not be a problem.

Cross text here (slightly different question, same answer).

+6
source

After trying several apkRename tools, I found that they all failed for some applications, such as com.android.browser on an HTC device.

The reason is apktool, which sometimes incorrectly decompresses the apk file.


So, I create my own tool: https://github.com/sjitech/ApkRename No need for apktool, no need for aapt, just java and jar utilities. This utility directly modifies AndroidManifest.xml, therefore, without recompiling the entire apktool resource, therefore it is clean.

Tested devices: 11 types (and Android 4+, but 2.2+ should not be OK) Tested OS: Mac OS X 10.9 and CentOS 6. (Cygwin with bash 4+ should be ok but not tested yet)

+4
source

I really tried the brad approach and could not imagine that I had to go through the process EVERY TIME, and I put together a release. so I did something else ... I modified the ADT so that it does not insert air. at the beginning and replaces it with a more useful extension, such as "com".

Here's a brief description of the approach:

usage: jar xf adt.jar

extract the adt.jar file to a directory on the desktop. you will find it in {adobe SDK} / lib /

Locate the APKOutputStream.class file

com / adobe / air / apk / APKOutputStream.class

Open it in a hex editor (e.g. HxD is what I used). Find the "air". (without quotes, but including a period).

Do not delete the entry. I tried, you cannot, it corrupts the class and it will not work. However, you can replace β€œair”. with "com". because it has the same number of characters and does not interfere with the length of the file. The com prefix is ​​much more useful for most of us.

save the modified APKOutputStream.class file and repackage it using the JAR. something like that:

jar cfm .. \ patchedadt.jar .. \ MANIFEST.MF *

you will want to copy this MANIFEST.MF file from the META-INF package subdirectory

Rename the file patchedadt.jar to adt.jar and put it back in the lib directory. Works with Flash Builder and all kinds of clothes.

Needless to say, when you are there, you will want to create your package without a β€œcom”. prefix so that you do not get into com.com.your.package.name.

there might have been an easier way, but I didn’t know anything better, and no one else had an answer but to decompile apk, modify it and recompile, and that didn't even work. so I decided that I would share what I did if someone else came across him later :)

Jim

+1
source

Source: https://habr.com/ru/post/908086/


All Articles