Let’s get our hands dirty
- Open android studio, and create two textView then set their values in onCreate Method. After that we build our application with Build -> Build Bunle APK -> Build APK. After getting apk file we can use our tool.
apktool d app-debug.apk
In our terminal go to folder that contains our debug apk file. Run this commad above. After code executes, new file is created same name with our apk name. Open this folder with vscode or some other code editor. Our folders are alike, but not perfectly identical. When we look at ‘MainActivity.smali’ in the ‘smali_classes3/com/example/{projectName}/’ folder, it relates to our ‘MainActivity.java’ class. Now, let’s compare these two files.
You might come across more confusing codes. These are Dalvik bytecode that we previously decompiled using apktool. While they might seem hard to grasp, here’s a cheat code to help make sense of it.
2. We’ll modify certain sections within the MainActivity.smali file. Look at lines 51 and 56; they contain strings defined in our code. Feel free to make any changes you want. Once done, remember to save the file.
3. we need to build our app. Paste code to our terminal below.
apktool b app-debug -o newapk.apk
4. We’ve got the ‘newapk.apk’ file with our latest changes. To install it on the emulator, we drag and drop the file onto the emulator window and watch as the app installs.
Before installing on our phone or simulator, we often deal with signing issues. To fix this, we’ll use two tools for signing.
In summary, for Android app development, keytool
is used to manage the keys and certificates necessary for signing APK files, and jarsigner
is employed to sign these APKs using those keys and certificates, establishing their authenticity and ensuring the security of the distributed Android applications.
5. Paste these codes to our terminal.
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
skip other steps with empty or write something that you want. Now we have keystore file. We will use it with jarsigner.
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore newapk.apk alias_name
6. Include these commands. After signing the ‘newapk.apk’ file, we can confidently reinstall the app on the emulator or phone. Once installed, you’ll observe the successful installation and notice your changes within the app. 👏👏👏👏👏👏👏