Android wrapper library around gomobile generated AAR library

36 views Asked by At

I want to make an Android library where most of the code is written in Go using Gomobile . Gomobile produces an .aar library when I run gomobile bind ....

I want to make a new library in Kotlin that internally uses the generated Gomobile library. The problem is that when I build my library and try to use it in an app, it crashes with the following error as soon as one of the generated Go functions are called.

JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception
java.lang.NoClassDefFoundError: Failed resolution of: Lmobile/ProtocolOptions

When comparing the contents of the AAR archives of my library with the Gomobile generated one, I can see that the jni directory is not copied over to my library.

I can make it work by also importing the Gomobile generated library in my application, but I would like to have them combined in a single library.


The configuration for my library is as follows.

- settings.gradle.kts
- library/
  - build.gradle.kts
  - src/...
- golibrary/
  - build.gradle.kts
  - gomobile-library.aar

settings.gradle.kts

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "Library"
include(":library")
include(":golibrary")

Library module build.gradle.kts

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
}

android {
    // Omitted...
}

dependencies {
    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.appcompat:appcompat:1.6.1")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

    // INCLUDE GO GENERATED LIBRARY
    implementation(project(mapOf("path" to ":golibrary")))
}

Gomobile library module build.gradle.kts

configurations.maybeCreate("default")
artifacts.add("default", file("gomobile-library.aar"))
0

There are 0 answers