如果我想在Android Studio中构建APK,我在这里有一点问题 我收到此错误消息:
Error:The number of method references in a .dex file cannot exceed 64K.
了解如何在https://developer.android.com/tools/building/multidex.html
解决此问题Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command '/usr/local/java/jdk1.8.0_77/bin/java'' finished with non-zero exit value 2
我在StackOverflow上找到了一个答案,该答案表示要在我的Gradle文件中编译这个依赖项:
compile 'com.android.support:multidex:1.0.0'
但这没有用。
这是我的Gradle文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:multidex:1.0.0'
}
答案 0 :(得分:3)
您需要在应用中启用多索引,方法是将multiDexEnabled
中的build.gradle
标记设置为true。请注意,您的最低SDK版本也必须为14或更高。
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
然后,在Manifest中配置Application元素:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
答案 1 :(得分:0)
在public static bool ContainsAny(this string self, params string[] criteria)
{
foreach (string s in criteria)
{
if (self.Contains(s))
{
return true;
}
}
return false;
}
if (myString.ContainsAny("UCK", "SAN", "AVB", "AVM", "SDS", "DWW", "WQP", "LHG"))
{
mySecondString = "CATEGORY A";
}
else if (myString.ContainsAny("UCT", "SAM", "AHJB", "AVR"))
{
mySecondString = "CATEGORY B";
}
else if (myString.ContainsAny("UKC", "SHZ", "EEB"))
{
mySecondString = "CATEGORY C";
}
else
{
mySecondString = "CATEGORY D";
}
文件中尝试此操作:
android { // }
然后在您的依赖项中添加以下内容:
build.gradle
<强>更新强>
如果要在项目中扩展Application,请切换到扩展它:
dexOptions {
javaMaxHeapSize "4g"
incremental true
preDexLibraries = false
}
最后,将您的应用程序名称设置为AndroidManifest文件
dependencies{
compile 'com.android.support:multidex:1.0.1'
}
这可以让你免于这个问题;祝你好运!