How to Change the SDK API Level to a 3rd Party Android APK

Sometimes your favorite Android app is one that is not available on the Play Store and hasn’t been updated in ages. You get your latest and greatest new phone/tablet, and now you are excited to install that one app not available on the Play Store. Suddenly you find out you cannot install it due to the Android SDK API target level being too low, or maybe the signature has expired and the app cannot be installed anymore.

Well, in this tutorial I will show you how to change the SDK API Level to a 3rd Party Android APK. It is easier than you might think, and you don’t even need Android Studio installed on your computer, or have awesome Java programming skills.

[topads][/topads]

Getting your Computer Ready

Make sure you have Java 1.8 or greater installed (needed for some of the tools we are going to be using). To find out what version of Java you are running, type the following command in your Terminal (macOS) or Command Prompt (Windows)

java -version

If you do not have Java installed, follow the official instructions.

Reverse Engineering the APK File

This is where you actually change the SDK API Level, but first you need to download Apktool. Head over to the official site and download the tool.

You will notice this is not your typical .dmg or .exe file, but rather a .jar file (basically a ZIP file containing Java class files and associated resources). In order to run it you need Java installed in your machine.

There are several actions Apktool can perform, but we are only concerned with two: decode and build.

Now we need the APK file we are wanting to update. For the sake of this example I will be using Anime Mobile, so I will refer to this file for the rest of the tutorial. When downloaded, this is the file name: com.anime.mobile.31.apk.

First, we need to decode the APK file. Open your Terminal or Command Prompt and navigate to the directory where you downloaded Apktool and type the following

java -jar apktool_2.3.4.jar d [Path to apk file]/com.anime.mobile.31.apk

You will see some output logs and the tool will create a directory in the same location of the tool and the same name as the APK file. In our case it will create com.anime.mobile.31 directory.

In Finder or Windows Explorer, navigate to com.anime.mobile.31 directory and open apktool.yml file. Towards the end you will find the line where you need to change the target SDK API Level, as the following

targetSdkVersion: "[API Level Version]"

Change the version number to the one you are wanting to use, save the file and close it.

Now it’s time to re-create the APK file. For that we will use the build command. Type the following in your Terminal or Command Prompt

java -jar apktool_2.3.4.jar b com.anime.mobile.31

Again you will see some logs, and after it finishes building the APK, open com.anime.mobile.31 directory and inside it you will see dist directory with the newly built APK file. At this point the file is not yet ready to be installed in your Android device. You will have to resign the APK file.

Getting the Necessary Command Line Tools

In order to sign the APK, we will need two command line tools: zipalign and apksigner. If you do not have Android Studio installed, you just have to download the SDK tools.

Once you have downloaded the tools and unzipped them, open Terminal or Command Prompt and navigate to tools -> bin. What we want is the sdkmanager command line utility.

Still under the bin directory, type the following

./sdkmanager --install "build-tools;26.0.3"

This will install the tools we need to sign our APK file under the build-tools directory (one level up from our current directory).

Note: Running ./sdkmanager –list will give you a listing of all the packages available for download, including different versions of the build-tools, platform-tools and other packages. The following is a sample output of the command

$ bin ./sdkmanager --list
Installed packages:=====================] 100% Computing updates...
Path | Version | Description | Location
------- | ------- | ------- | -------
platform-tools | 27.0.1 | Android SDK Platform-Tools 27.0.1 | platform-tools/
platforms;android-26 | 2 | Android SDK Platform 26 | platforms/android-26/
tools | 26.1.1 | Android SDK Tools 26.1.1 | tools/

Available Packages:
Path | Version | Description
------- | ------- | -------
add-ons;addon-google_apis-google-15 | 3 | Google APIs
add-ons;addon-google_apis-google-16 | 4 | Google APIs
add-ons;addon-google_apis-google-17 | 4 | Google APIs
add-ons;addon-google_apis-google-18 | 4 | Google APIs
add-ons;addon-google_apis-google-19 | 20 | Google APIs
add-ons;addon-google_apis-google-21 | 1 | Google APIs
add-ons;addon-google_apis-google-22 | 1 | Google APIs
add-ons;addon-google_apis-google-23 | 1 | Google APIs
add-ons;addon-google_apis-google-24 | 1 | Google APIs
add-ons;addon-google_gdk-google-19 | 11 | Glass Development Kit Preview
build-tools;19.1.0 | 19.1.0 | Android SDK Build-Tools 19.1
build-tools;20.0.0 | 20.0.0 | Android SDK Build-Tools 20
build-tools;21.1.2 | 21.1.2 | Android SDK Build-Tools 21.1.2
build-tools;22.0.1 | 22.0.1 | Android SDK Build-Tools 22.0.1
build-tools;23.0.1 | 23.0.1 | Android SDK Build-Tools 23.0.1
build-tools;23.0.2 | 23.0.2 | Android SDK Build-Tools 23.0.2
build-tools;23.0.3 | 23.0.3 | Android SDK Build-Tools 23.0.3
build-tools;24.0.0 | 24.0.0 | Android SDK Build-Tools 24
build-tools;24.0.1 | 24.0.1 | Android SDK Build-Tools 24.0.1
build-tools;24.0.2 | 24.0.2 | Android SDK Build-Tools 24.0.2
...

Once you have downloaded the build-tools, in your Terminal or Command Prompt navigate to the build-tools/26.0.3 directory.

cd ../build-tools/26.0.3

Signing The APK File

Before using the utilities provided by the build tools, you will need to generate a private key file with a Java utility. Type the following in your Terminal or Command Prompt

keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

Follow the steps indicated by the utility, and remember the password because you will use it later when signing the APK file. After you finish with the steps, a file named my-release-key.jks will be generated.

Still in your Terminal or Command Prompt under the build-tools/26.0.3 directory, type the following

./zipalign -v -p 4 [your path]/com.anime.mobile.31/dist/com.anime.mobile.31.apk [your path]/com.anime.mobile.31/dist/com.anime.mobile.31-aligned.apk

Basically the first APK file in the command is the one that was generated by Apktool and the second one is the one zipalign will create (com.anime.mobile.31-aligned.apk).

From the official documentation: zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which may reduce the amount of RAM consumed by an app.

Finally we are ready to sign the APK file so we can install it in our Android device. Type the following in your Terminal or Command Prompt

./apksigner sign --ks my-release-key.jks --out [your path]/com.anime.mobile.31/dist/com.anime.mobile.31-release.apk [your path]/com.anime.mobile.31/dist/com.anime.mobile.31-aligned.apk

This command will ask you for the password you entered when generating the private key file. The first APK file listed in the command is the one that will get generated by apksigner utility (com.anime.mobile.31-release.apk) and the second one listed is the one generated by zipalign utility.

Conclusion

Now that you have the signed APK file, just move it to your Android device and proceed with the installation.

Well, that was a lot of steps and it took me several hours to figure everything out and hopefully this guide sped up your endeavor! That being said, I hope you can share this article on your social media pages 🙂

You can follow me on Twitter and GitHub.

Thank you for reading and I hope you enjoyed it. If you have any questions or suggestions let me know in the comments below!

Resources

[bottomads][/bottomads]

Spread the love

One thought on “How to Change the SDK API Level to a 3rd Party Android APK

  1. Robra says:

    Olá Esau.
    Como vai?
    Fiz este processo pelo Easy Tool Apk 1.56 para um app que estava fechando assim que o abria, aparecendo a seguinte mensagem: “Esse aplicativo foi criado para uma versão mais antiga do Android e pode não funcionar corretamente. Tente verificar se há atualizações ou entre em contato com o desenvolvedor.”
    No arquivo apktool.yml nas linhas minSdkVersion: ‘8’ e targetSdkVersion: ‘8’, eu mudei para ’26’ e ’28’ respectivamente.
    O app rodava de boa em meu celular com o Lollipop 5.1.1 mas o problema supracitado apareceu quando o instalei em meu novo celular com o Pie 9.
    A mensagem de erro sumiu mas o app continua fechando assim que pressiono o ícone para abri-lo.
    Embora o desenvolvedor ainda exista, ele abandonou a atualização do app.
    Gostaria da saber se para deixá-lo funcional no Pie 9 é muito complicado, porque este app me ajuda bastante.
    Desde já, agradeço pela atenção dispensada.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.