我遇到了一个奇怪的问题 昨天,在将子模块中的代码从java更改为kotlin之后,我得到了'.dex文件中的方法引用数量不能超过64K。' 我的应用程序在更改代码之前工作正常,它的build.gradle看起来像:
defaultConfig {
...
//multiDexEnable true // spelling error has been corrected
multiDexEnabled true
...
}
dependencies {
...
compile 'com.android.support:multidex:1.0.3'
...
}
我的包结构如下:
App。
--sharemodule。
--othermodule。
sharemodule和othermodule是我的App的子模块。
我刚刚在sharemodule中减少了一些未使用的代码,并将其代码更改为kotlin,然后出现了这个问题。
请帮助我,谢谢。
感谢您的回复,我更正了拼写错误。该应用程序还扩展了'MultiDexApplication'
public class App extends MultiDexApplication {
我已经尝试了这个link,但没有用。
我还应该在模块的build.gradle中添加'multiDexEnabled true'吗?目前我只是将其添加到我的应用程序的build.gradle中。
答案 0 :(得分:2)
multiDexEnabled
不是multiDexEnable
。因此,请在gradle文件中更改 defaultConfig 。
电流:
defaultConfig {
...
multiDexEnable true
...
}
更改为:
defaultConfig {
...
multiDexEnabled true
...
}
请查看此链接以获取更多信息:https://developer.android.com/studio/build/multidex.html#mdex-gradle
阅读此链接以了解有关为超过64K方法的应用启用Multidex的更多信息:https://developer.android.com/studio/build/multidex.html
答案 1 :(得分:0)
像这样使用 Multidex :
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
喜欢这个
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
目前您使用
multiDexEnable true
更改为
multiDexEnabled true
它可以帮助你尝试这个。
答案 2 :(得分:0)
关注此事 - >
第1步:在您的应用级build.gradle
defaultConfig {
...
multiDexEnabled true
...
}
第2步:将此依赖关系添加到您的应用级build.gradle
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
...
}
第3步:创建extends
Application
类
public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
//ActiveAndroid.initialize(this);
mInstance = this;
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
public static synchronized AppController getInstance() {
return mInstance;
}
public AppController() {
super();
}
}
第4步:将其添加到application
AndroidManifest.xml
标记
<application
android:name="com.relyfy.adapter.AppController"
.... >