Search code examples
androidkotlingradlegodot

Android APK crashes when LicensingServiceHelper is initialized


I have an Android project that builds an AAR file library. When I include this AAR file in my Godot (v3.5.2) project and export it as an Android APK, the program crashes when I call a function in Godot that results in the following Kotlin code being run:

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

My LicensingServiceHelper.java is as follows:

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;
    }
}

An excerpt of my logcat is as follows:

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

My app's build.gradle is as follows:

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

I can provide more of my project files if needed.


Solution

  • It seems the issue was related to my Godot Android plugin's .gdap file not being set up correctly.

    Changing GodotPlayGamesServices.gdap from

    [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"]
    

    to

    [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"]
    

    and placing the licensingservicehelper-release.aar file in the Godot project's android/plugins directory caused the APK to run without crashing when exported in Godot.