Unable to run Libgdx Game after adding Mapbox sdk to build.gradle

java android libgdx build.gradle mapbox

121 观看

1回复

14 作者的声誉

I'm getting this error in logcat:

12-27 17:39:51.213 3365-3365/com.mksolutions.platformerap E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.mksolutions.platformerap, PID: 3365
 java.lang.ExceptionInInitializerError
     at java.lang.Class.newInstance(Native Method)
     at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781)
     at android.app.ActivityThread.-wrap12(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:241)
     at android.app.ActivityThread.main(ActivityThread.java:6274)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  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:125)
     at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:33)
     at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:63)
     at java.lang.Class.newInstance(Native Method) 
     at android.app.Instrumentation.newActivity(Instrumentation.java:1079) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781) 
     at android.app.ActivityThread.-wrap12(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:241) 
     at android.app.ActivityThread.main(ActivityThread.java:6274) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
  Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.mksolutions.platformerap-2/base.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.mksolutions.platformerap-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mksolutions.platformerap-2/lib/arm64, /data/app/com.mksolutions.platformerap-2/base.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.mksolutions.platformerap-2/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libgdx.so"
     at java.lang.Runtime.loadLibrary0(Runtime.java:984)
     at java.lang.System.loadLibrary(System.java:1530)
     at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:119)
     at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:33) 
     at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:63) 
     at java.lang.Class.newInstance(Native Method) 
     at android.app.Instrumentation.newActivity(Instrumentation.java:1079) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781) 
     at android.app.ActivityThread.-wrap12(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:241) 
     at android.app.ActivityThread.main(ActivityThread.java:6274) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

I began getting this error after adding in my implementation of Mapbox. To be more precise, These lines in my build.gradle dependencies makes the error:

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.2.0@aar') {
    transitive = true
}

The App crashes as soon as I press the button that launches the game. After pressing the button, this code runs:

Intent intent = new Intent(getActivity(), PlatformerLauncher.class);
getActivity().startActivity(intent);

Which in turn runs this class:

public class PlatformerLauncher extends AndroidApplication {

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    initialize(new GamePlatformer(), config);
   }
}

Content of GamePlatformer:

public class GamePlatformer extends Game{
public SpriteBatch batcher;
@Override
public void create() {
    Gdx.input.setCatchBackKey(true);
    batcher = new SpriteBatch();
    //load assets
    Assets.load();

    //draw game
    setScreen(new PlatformerGameScreen(this));
}

@Override
public void render()
{
    super.render();
}
}

And finally full build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.mksolutions.platformerap"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDir 'libs'
        }
    }
}
configurations { natives }
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.2.0@aar') {
        transitive = true
    }

    compile project(':common')
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"

    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.github.kenglxn.QRGen:android:2.3.0'
    compile 'com.google.android.gms:play-services-vision:11.0.4'
    compile 'com.google.android.gms:play-services-location:11.0.4'
    testCompile 'junit:junit:4.12'
}

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

Does someone have a suggestion for what I'm doing wrong?

作者: Muhsin 的来源 发布者: 2017 年 12 月 27 日

回应 1


0

14 作者的声誉

决定

Found out that the android device tried to access libraries, which weren't there.

The solution:

add This to defaultConfig in build.gradle:

    defaultConfig {
        ...
        ndk {
            abiFilters "armeabi-v7a", "x86", "armeabi"
        }
    }

And add this line inside gradle.properties:

android.useDeprecatedNdk=true

Re-sync gradle.

作者: Muhsin 发布者: 2018 年 1 月 1 日
32x32