
zipalign -f 4 $PROJ/bin/ $PROJ/bin/hello.apkĪlignment increase the performance of the application and may reduce memory use. Note that apksigner only exist since Build Tools 24.0.3. apksigner sign -ks mykey.keystore $PROJ/bin/hello.apk Just answer the questions and put a password. To do so, we firstly create a new keystore with the command keytool given by Java: keytool -genkeypair -validity 365 -keystore mykey.keystore -keyalg RSA -keysize 2048 If you want, you can check the content of the package like this.
#ANDROID STUDIO LINUX TUTORIAL ANDROID#
The generated package can’t be installed by Android because it’s unaligned and unsigned.
#ANDROID STUDIO LINUX TUTORIAL APK#
You have to copy the x file at the root of project like above! Otherwise, AAPT won’t put this file at right place in the APK archive (because an APK is like a. aapt add $PROJ/bin/ xīe aware: until now, we used three AAPT commands, the first and the second one are similar but they don’t do the same. aapt package -f -m -F $PROJ/bin/ -M $PROJ/AndroidManifest.xml -S $PROJ/res -I /opt/android-sdk/platforms/android-19/android.jar cp $PROJ/bin/x. Note that we can use previous versions of Java even we use OpenJDK 8 (or 1.8). The -source option specify the java version of your source files. To solve the problem, you have to specify 1.7 java version in the previous javac command: cd /path/to/AndroidHello javac -d obj -source 1.7 -target 1.7 -classpath src -bootclasspath /opt/android-sdk/platforms/android-19/android.jar src/com/example/helloandroid/*.java If you have the error UNEXPECTED TOP-LEVEL EXCEPTION, it can be because you use old build tools and DX try to translate java 1.7 rather than 1.8. dx -dex -output=$PROJ/bin/x $PROJ/*.jar $PROJ/obj

dx -dex -output=$PROJ/bin/x $PROJ/objīut if you use external libraries, do rather. We have to translate them in a file called “x” which will be read by the dalvik Android runtime: cd /opt/android-sdk/build-tools/26.0.1/. class files are in obj folder, but Android can’t read them. If you have use an external, add it the classpath: javac -d obj -classpath "src:libs/.jar" -bootclasspath /opt/android-sdk/platforms/android-19/android.jar src/com/example/helloandroid/*.java java files: cd /path/to/AndroidHello javac -d obj -classpath src -bootclasspath /opt/android-sdk/platforms/android-19/android.jar src/com/example/helloandroid/*.java

You can find yours in a location like android-sdk/platforms/android-/android.jar -I tells aapt where the android.jar is.-S specifies where is the res directory with the drawables, layouts, etc.Saying -J src will create a file like src/com/example/helloandroid/R.java

-m instructs aapt to create directories under the location specified by -J.aapt package -f -m -J $PROJ/src -M $PROJ/AndroidManifest.xml -S $PROJ/res -I /opt/android-sdk/platforms/android-19/android.jar Now, I recommend to store the project path in a variable: export PROJ=path/to/HelloAndroidįirst, we need generate the R.java file which is necessary for our code: cd /opt/android-sdk/build-tools/26.0.1/.
