使用libgdx

时间:2015-11-17 19:51:16

标签: java android libgdx android-gradle build.gradle

  

我正在学习使用libgdx构建游戏,我使用gdx-setup生成了项目。该项目正在编译,它在调试模式下运行正常。   但是当你把它编译成签名的apk时,它在正确安装时出现问题,我收到了错误"应用程序未安装"。我知道问题不在于密钥,因为它适用于没有使用libgdx的apk。

如果有人遇到同样的错误,请告知。

我使用以下版本的软件/库
 1. Android studio v1.4
 2. Libgdx v1.7.0

以下是Build.gradle文件的示例代码

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']
    }
}
}

2 个答案:

答案 0 :(得分:1)

我建议您确认您已完成以下操作:

1-卸下您的应用程序(如果它已存在于您的手机中)

2-增加apk versionCode的数量(如果它不是你拥有的第一个版本)

3-确认您没有将相同的密钥用于您的其他应用程序

4 - 执行:设置 - >安全 - >设备管理 - >检查了未知来源

希望这会有所帮助

祝你好运

答案 1 :(得分:1)

您签名的apk可能不是zip对齐的。

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

我个人从android studio构建一个unsigned_release apk。 (您可以在左下角的android studio中选择Build Variants。选择release。) 之后,我打开 project \ android \ build \ outputs \ apk \ release ** 它将包含一个** android-release-unsigned.apk

我没有为libgdx项目使用android studio签名的apk生成机制。相反,我选择上面创建的android-release-unsigned.apk并使用Java jarsigner。

基本上,您需要像这样用jarsigner对其进行签名

%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"

,然后将其对齐(可能会更改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"

这是一个Windows批处理文件,希望可以使您更轻松

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"