使用 libgdx 应用在 Eclipse 中启用 multidex
Posted
技术标签:
【中文标题】使用 libgdx 应用在 Eclipse 中启用 multidex【英文标题】:Enable multidex in Eclipse with libgdx app 【发布时间】:2017-06-22 10:27:47 【问题描述】:我不知道为什么 multidex 不适合我。我将 Eclipse 和 Gradle 与 libgdx 应用程序一起使用。我认为我已经完成了谷歌所说的一切,但仍然出现错误:
转换为 Dalvik 格式失败:无法执行 dex:方法 ID 不在 [0, 0xffff]: 65536
这是我在 android 项目中的 build.gradle:
android
buildToolsVersion "23.0.2"
compileSdkVersion 23
sourceSets
main
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
instrumentTest.setRoot('tests')
defaultConfig
minSdkVersion 14
// Enabling multidex support.
multiDexEnabled true
dexOptions
javaMaxHeapSize "4g"
buildTypes
release
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
dependencies
compile 'com.android.support:multidex:1.0.0'
我什至将“SDK\extras\android\support\multidex\library”中的 multidex 项目作为库添加到我的 Android 项目中。这是我的 AndroidManifest.xml 的一部分:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
package="XXXXXXXXXXXXXXXXXXXXXXX"
android:versionCode="175"
android:versionName="5.0.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:allowBackup="false"
android:name="android.support.multidex.MultiDexApplication" >
<activity android:name="XXXXXXXXXXXXXXX.XXXXXXXXX.BTActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="XXXX.XXXXXX.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
</activity>
</application>
</manifest>
在我的 AndroidLauncher 类中,我有:
public class AndroidLauncher extends AndroidApplication implements AdActionResolver, GSActionResolver, GameHelperListener
@Override
protected void attachBaseContext(Context base)
super.attachBaseContext(base);
MultiDex.install(this);
谁能告诉我这个配置有什么问题?也许我应该迁移到 Android Studio?
【问题讨论】:
【参考方案1】:documentation 说:
根据您是否覆盖 Application 类,执行以下一个
所以你确实在清单中设置了这个:
android:name="android.support.multidex.MultiDexApplication"
这应该足够了,除非你在某处覆盖 Application
类。
但是您也将此代码放在 AndroidLauncher
类中(这是 Activity
,而不是 Application
- 名称令人困惑,请参阅 LibGDX javadoc)
@Override
protected void attachBaseContext(Context base)
super.attachBaseContext(context);
Multidex.install(this);
所以请删除此代码并检查它是否解决了问题。
您还应该阅读Limitations of the multidex support library。
此外,我建议您在 gradle 脚本中指定 minSdkVersion
时从清单中删除 <uses-sdk>
标签。
【讨论】:
我已经删除了 attachBaseContext 方法的覆盖,但仍然出现错误。我也删除了以上是关于使用 libgdx 应用在 Eclipse 中启用 multidex的主要内容,如果未能解决你的问题,请参考以下文章
Android libGDX:使用 google-play-services_lib 时 Eclipse 崩溃
如何在 libGDX for Android 中使用 MultiDexApplication