1

For a little game project, we have to use gradle-experimental to include shared library and use the NDK, and for the graphics we use the libgdx.

Before, we used not experimental gradle and the libgdx works, but now we have an exception :

FATAL EXCEPTION: main
                                                                       Process: eu.epitech.gomoku.android, PID: 28180
                                                                           java.lang.ExceptionInInitializerError
                                                                               at java.lang.Class.newInstance(Native Method)
                                                                               at android.app.Instrumentation.newActivity(Instrumentation.java:1090)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:148)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                                                                            Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx' for target: Linux, 32-bit
                                                                               at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:118)
                                                                               at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:34)
                                                                               at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:61)
                                                                               at java.lang.Class.newInstance(Native Method) 
                                                                               at android.app.Instrumentation.newActivity(Instrumentation.java:1090) 
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) 
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:148) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                                                                            Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/eu.epitech.gomoku.android-1/base.apk"],nativeLibraryDirectories=[/data/app/eu.epitech.gomoku.android-1/lib/arm64, /data/app/eu.epitech.gomoku.android-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libgdx.so"
                                                                               at java.lang.Runtime.loadLibrary(Runtime.java:367)
                                                                               at java.lang.System.loadLibrary(System.java:1076)
                                                                               at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:113)
                                                                               at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:34) 
                                                                               at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:61) 
                                                                               at java.lang.Class.newInstance(Native Method) 
                                                                               at android.app.Instrumentation.newActivity(Instrumentation.java:1090) 
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) 
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:148) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 

My gradle files :

ProjectRoot

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "Gomoku"
        gdxVersion = '1.7.1'
        roboVMVersion = '1.9.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.6.0'
    }

    repositories {
        jcenter()
    }
}

project(":android") {
    apply plugin: "com.android.model.application"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

Android Folder :

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            applicationId = "eu.epitech.gomoku.android"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 23
            versionCode = 4
            versionName = "1.0.1"
        }
    }

    android.ndk {
        moduleName = "GomokuRules"
        cppFlags.add("-I${file("jni/headers/")}".toString())
        stl = "c++_shared"
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }

    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }

    android.sources {
        main {
            manifest {
                source {
                    srcDir '.'
                    include 'AndroidManifest.xml'
                }
            }
            resources {
                source {
                    srcDir 'res/'
                }
            }
            assets {
                source {
                    srcDir 'assets/'
                }
            }
            java {
                source {
                    srcDir 'src/eu/epitech/gomoku/android/'
                }
            }
            jniLibs {
                source {
                    srcDir 'libs/'
                }
            }
        }
    }

}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
    file("src/main/libs/armeabi/").mkdirs();
    file("src/main/libs/armeabi-v7a/").mkdirs();
    file("src/main/libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("src/main/libs/armeabi-v7a")
        if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("src/main/libs/armeabi")
        if (jar.name.endsWith("natives-x86.jar")) outputDir = file("src/main/libs/x86")
        if (outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}

task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'eu.epitech.gomoku.android/eu.epitech.gomoku.android.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [project.configurations.compile]
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}

// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");scopes = [ COMPILE: [plus: [project.configurations.compile]]]

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES" , value:"true")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
    compile 'com.android.support:support-v4:23.+'
}
Maxime Limone
  • 121
  • 11
  • perhaps this can help: http://stackoverflow.com/questions/21806778/couldnt-load-shared-library-gdx-for-target – asherbret Dec 30 '15 at 09:51

0 Answers0