初始化 LicensingServiceHelper 时 Android APK 崩溃

问题描述 投票:0回答:1

我有一个构建AAR文件库的Android项目。当我在 Godot (v3.5.2) 项目中包含此 AAR 文件并将其导出为 Android APK 时,当我调用 Godot 中的函数并导致运行以下 Kotlin 代码时,程序崩溃:

val lsh = LicensingServiceHelper(godot.activity as Activity, "<REDACTED>")

我的

LicensingServiceHelper.java
如下:

public class LicensingServiceHelper {

    private static final String TAG = "LicensingServiceHelper";

    private final Activity context;
    private final String publicKey;
    private LicensingServiceCallback callback;

    private ILicensingService licensingService;
    private ServiceConnection serviceConnection =
            new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder binder) {
                    licensingService = ILicensingService.Stub.asInterface(binder);
                    Log.d(TAG, "Service connected");
                }
                @Override
                public void onServiceDisconnected(ComponentName name) {
                    licensingService = null;
                    Log.d(TAG, "Service disconnected");
                }
            };

    public LicensingServiceHelper(Activity activity, String publicKey) {
        this.context = activity;
        this.publicKey = publicKey;
    }
}

我的logcat摘录如下:

05-04 01:55:17.834 21847 21875 E Surface : freeAllBuffers: 1 buffers were freed while being dequeued!
05-04 01:55:17.840 21847 21875 W libEGL  : eglTerminate() called w/ 1 objects remaining
05-04 01:55:17.841 21847 21875 E AndroidRuntime: FATAL EXCEPTION: GLThread 514
05-04 01:55:17.841 21847 21875 E AndroidRuntime: Process: com.trampolinetales.lbal, PID: 21847
05-04 01:55:17.841 21847 21875 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/licensingservicehelper/LicensingServiceHelper;
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    at io.cgisca.godot.gpgs.PlayGameServicesGodot.signIn(PlayGameServicesGodot.kt:239)
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    at org.godotengine.godot.GodotLib.step(Native Method)
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    at org.godotengine.godot.GodotRenderer.onDrawFrame(GodotRenderer.java:57)
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    at org.godotengine.godot.gl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1576)
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    at org.godotengine.godot.gl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1278)
05-04 01:55:17.841 21847 21875 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: com.google.licensingservicehelper.LicensingServiceHelper
05-04 01:55:17.841 21847 21875 E AndroidRuntime:    ... 5 more
05-04 01:55:17.843  1469 21906 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
05-04 01:55:17.843  1469  1500 W ActivityTaskManager:   Force finishing activity com.trampolinetales.lbal/com.godot.game.GodotApp
05-04 01:55:17.854 21847 21875 I Process : Sending signal. PID: 21847 SIG: 9

我的应用程序的

build.gradle
如下:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
    compileSdk 33
    namespace 'io.cgisca.godot.gpgs'
    def libName = project.property("library_name")
    defaultConfig {

        targetSdk 33
        buildConfigField "String", "LIBRARY_NAME", "\"$libName\""
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    defaultConfig {
        minSdkVersion 21
        versionCode 1
        versionName "1.0"
    }


    libraryVariants.all { variant ->
        variant.outputs.all { output ->
            output.outputFileName = "$libName.${variant.name}.aar"
        }
    }

    buildFeatures {
        viewBinding true
        buildConfig true
        aidl true
    }
    buildToolsVersion '33.0.0'
}

dependencies {
    compileOnly fileTree(dir: '../libs', include: ['godot-lib*.aar'])
    implementation project(":licensingservicehelper")
    implementation "org.bitbucket.b_c:jose4j:0.9.6"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'com.google.android.play:integrity:1.3.0'
    implementation 'com.google.android.gms:play-services-games:23.1.0'
    implementation 'com.google.android.gms:play-services-auth:21.1.1'
    implementation 'com.google.android.gms:play-services-location:21.2.0'
    implementation 'com.google.code.gson:gson:2.8.9'
    testImplementation 'junit:junit:4.13.2'
}

如果需要,我可以提供更多我的项目文件。

java android kotlin gradle godot
1个回答
0
投票

问题似乎与我的 Godot Android 插件的

.gdap
文件设置不正确有关。

GodotPlayGamesServices.gdap
更改为

[config]

name="GodotPlayGamesServices"
binary_type="local"
binary="GodotPlayGamesServices.release.aar"

[dependencies]

remote=["com.google.android.gms:play-services-games:23.1.0", "com.google.android.gms:play-services-auth:20.5.0", "com.google.android.gms:play-services-location:21.0.1", "com.google.code.gson:gson:2.8.9"]

[config]

name="GodotPlayGamesServices"
binary_type="local"
binary="GodotPlayGamesServices.release.aar"

[dependencies]

local=["licensingservicehelper-release.aar"]
remote=["org.bitbucket.b_c:jose4j:0.9.6", "com.google.android.gms:play-services-games:23.1.0", "com.google.android.gms:play-services-auth:21.1.1", "com.google.android.gms:play-services-location:21.2.0", "com.google.code.gson:gson:2.8.9"]

并将

licensingservicehelper-release.aar
文件放在 Godot 项目的
android/plugins
目录中,导致 APK 在 Godot 中导出时运行而不会崩溃。

© www.soinside.com 2019 - 2024. All rights reserved.