无法加入Mapbox SDK来的build.gradle

我在logcat中获取此错误后运行Libgdx游戏:无法加入Mapbox SDK来的build.gradle

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) 

我开始在我的实现Mapbox的加入后收到此错误。更精确地说,在我的build.gradle依赖这些线使错误:

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]') { 

transitive = true

}

应用程序,只要我按一个启动游戏的按钮崩溃。 按下该按钮后,运行此代码:

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

getActivity().startActivity(intent);

这反过来又运行这个类:GamePlatformer的

public class PlatformerLauncher extends AndroidApplication { 

@Override

protected void onCreate (Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

initialize(new GamePlatformer(), config);

}

}

内容:

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();

}

}

最后完全的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:[email protected]') {

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"

}

}

}

}

有人对我做错了什么有什么建议吗?

回答:

发现安卓设备试图访问库,这不在那里。

解决办法:

这的build.gradle添加到defaultConfig:

defaultConfig { 

...

ndk {

abiFilters "armeabi-v7a", "x86", "armeabi"

}

}

,往其中加gradle.properties这一行:

android.useDeprecatedNdk=true 

重新同步gradle这个。

以上是 无法加入Mapbox SDK来的build.gradle 的全部内容, 来源链接: utcz.com/qa/266503.html

回到顶部