Kevin
Kevin

Reputation: 73

Issue on signed apk using libgdx

I'm learning to build game using libgdx, I have generated the project using the gdx-setup. The project is compiling and it run fine on the debugging mode. But when you compile it into a signed apk, it has issue on installing correctly, i got the error "App not installed". I know that the problem is not with the key because it work fine with an apk that is not using libgdx.

Please let know if anyone is encountering the same error.

I'm using the below version for software/library
1. Android studio v1.4
2. Libgdx v1.7.0

Below is the sample code for the Build.gradle file

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.testgdx.game.android"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

signingConfigs {
    release {
        storeFile file('key.jks')
        storePassword "storepassword"
        keyAlias "appkey"
        keyPassword "keypassword"
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
        jniLibs.srcDirs = ['libs']
    }
}
}

Upvotes: 1

Views: 1081

Answers (2)

zeg
zeg

Reputation: 586

Your signed apk is propably not zip-aligned.

https://developer.android.com/studio/command-line/zipalign

Personally i build an unsigned_release apk from android studio. (you can select Build Variants in android studio on the bottom left corner. Choose release.) Afterwards i open project\android\build\outputs\apk\release** it will contain an **android-release-unsigned.apk

I do not use android studio signed apk build mechanism for libgdx projects. Instead i pick the above created android-release-unsigned.apk and use Java jarsigner.

Basically you need to sign it with jarsigner like this

%JAVA_HOME%/bin/jarsigner.exe -verbose -keystore "path/to/your/signing/keystore.jks" -storepass "yourjkskeystorepassword" -keypass "aliaspassword" "android\build\outputs\apk\release\android-release-unsigned.apk" "aliasname"

and afterwards zipalign it (maybe change the version of your android sdk build-tools-path)

%ANDROID_HOME%/build-tools/28.0.3/zipalign.exe 4 "android\build\outputs\apk\release\android-release-unsigned.apk" "android\build\outputs\apk\release\android-release-ready_x32.apk"

Here is a windows batch file that hopefully makes it a little easier for you

REM ### make sure that you created an android-release-unsigned.apk file within C:\Users\YOURNAME\AndroidStudioProjects\libgdx\YOURPROJECT\android\build\outputs\apk\release\android-release-unsigned.apk
REM ### 
REM ### just execute this as a .bat file in YOURPROJECT-directory or windows CMD
REM ### 
REM ### set variables for signing your jar/apk with your signing-certificate
set /p certpath="Enter the path to your signing-certificate-keystore (jks) "
set /p singcertJKSkeystorepassword="Enter your jks keystore password "
set /p aliasName="Enter Alias Name "
set /p aliasPassword="Enter Alias Password "
REM ### now sign the release-candidate apk
"%JAVA_HOME%\bin\jarsigner.exe" -verbose -keystore "%certpath%" -storepass "%singcertJKSkeystorepassword%" -keypass "%aliasPassword%" "android\build\outputs\apk\release\android-release-unsigned.apk" "%aliasName%"
COPY "android\build\outputs\apk\release\android-release-unsigned.apk" "android\build\outputs\apk\release\android-release-signed.apk"
REM ### and since we used jarsigner align the zip afterwards (see google android documentation)
REM ### you probably need to change the build-tools version
"%ANDROID_HOME%\build-tools\28.0.3\zipalign.exe" 4 "android\build\outputs\apk\release\android-release-signed.apk" "android\build\outputs\apk\release\android-release-signed-and-aligned_x32.apk"
"%ANDROID_HOME%\build-tools\28.0.3\zipalign.exe" 8 "android\build\outputs\apk\release\android-release-signed.apk" "android\build\outputs\apk\release\android-release-signed-and-aligned_x64.apk"
REM ### that is it. use the _x32 aligned one to upload into google playstore, this means 32bit-zip-alignment, this has no effect on code-execution
set /p exit="Press ENTER to exit"

Upvotes: 2

Netero
Netero

Reputation: 3819

I propose to you to verify that you have done the following :

1- unstall your application (if it already exist in your phone)

2- Increase the number of the apk versionCode (if it is not the first version you have)

3- Verify that you 're not using the same key for other applications of yours

4 - Do : Settings -> Security -> Device Administration -> Unknown sources checked

Hope this will be helpful

Good luck

Upvotes: 1

Related Questions