Android application install warning (built for older version)

Viewed 748

I followed this tutorial to build Android application from command line. This is my batch script to build and install the application on my device using USB debugging.

aapt package -f -m -J build\gen\ -S res -M AndroidManifest.xml -I "%ANDROID_HOME%\platforms\android-30\android.jar"

javac -source 1.7 -target 1.7 -bootclasspath "%JAVA_HOME%\jre\lib\rt.jar" -classpath "%ANDROID_HOME%\platforms\android-30\android.jar" -d build\obj build\gen\net\hanshq\hello\R.java src\net\hanshq\hello\MainActivity.java

java -jar "%ANDROID_HOME%\build-tools\30.0.0\lib\dx.jar" --dex --output=build\apk\classes.dex build\obj

aapt package -f -M AndroidManifest.xml -S res\ -I "%ANDROID_HOME%\platforms\android-30\android.jar" -F build\Hello.unsigned.apk build\apk

zipalign -f -p 4 build\Hello.unsigned.apk build\Hello.aligned.apk

call apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android --key-pass pass:android --out build\Hello.apk build\Hello.aligned.apk

adb install -r build\Hello.apk

adb shell am start -n net.hanshq.hello/.MainActivity

I use OpenJDK-17, Android-30 platform version, and Android 30.0.0 build tools version.

This is the AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="net.hanshq.hello"
          versionCode="1"
          versionName="0.1">
    <uses-sdk android:minSdkVersion="30"/>
    <application android:label="Hello">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

What I want to ask is when I set the minSdkVersion to 30 it installed fine on my device. But, when I set it to a lower value like 21, it still installed correctly but output a warning popout like this.

This app was built for an older version of Android and may not work properly. Try checking for updates, or contact the developer.

What I want to ask is this warning related to value of minSdkVersion or is it because the version of Android SDK platform and build tools that I used? Thanks in advance for the answer.

Edit: My device is running Android 11 OS

1 Answers

I managed to get rid of the error by

  1. specifying a min sdk version of 21 , targetSdkVersion and maxSdkVersion
  2. changing the source jdk version from 1.7 to 11 in the javac command
  3. using d8 to change class files to dex files in build-tools version 32

here's my build script for reference:

target=$1

if  [ "$1" = "" ]; then
    target="a.apk"
fi



aapt package -f -v \
    -I ~/android-sdk/platforms/android-32/android.jar \
    -J src -m \
    -M AndroidManifest.xml \
    -S res \
    -F bin/resources.ap_

javac \
    -classpath ~/android-sdk/platforms/android-32/android.jar \
  -source 11 -target 11 \
    src/dom/domain/*.java

d8 --output bin src/*/*/*.class \
  --lib ~/android-sdk/platforms/android-32/android.jar 

cd bin

mv resources.ap_    $target

aapt add    $target classes.dex

printf 'android\n' | apksigner sign --min-sdk-version 29 \
  --v4-signing-enabled true \
  -ks ~/code/android/debug.keystore $target

adb install --no-incremental -r $target


Related