我正在用SugarORM库构建一个应用程序,但当我尝试为API 17构建项目时(没有检查其他人),它显示构建错误。
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72330Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2330Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2330Library UP-TO-DATE
:app:prepareComAndroidVolleyVolley100Library UP-TO-DATE
:app:prepareComGithubSatyanSugar14Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppstate840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesDrive840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesFitness840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGames840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIdentity840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesNearby840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPanorama840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPlus840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWallet840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable840Library UP-TO-DATE
:app:prepareMeDrakeetMaterialdialogLibrary131Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:prePackageMarkerForDebug
:app:transformClassesWithDexForDebug
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at 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 '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 21.663 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console
但是当我为android v5.0或更高版本构建这个项目时,它工作得很好。如果我删除SugarORM gradle依赖项,它可以在v4.2.2和v5.0设备上正常工作。
你的方法太多了。dex只能有65536个方法。
正如建议的那样,您可以使用multidex支持。
只需在/build.gradle模块中添加这些行:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1' //with androidx libraries
//implementation 'com.android.support:multidex:1.0.3' //with support libraries
}
或者如果使用module/build.gradle.kts:
android {
// other properties
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled = true
}
...
}
dependencies {
implementation("androidx.multidex:multidex:2.0.1") // with androidx libraries
// implementation("com.android.support:multidex:1.0.3") // with support libraries
}
同样在清单中,将multidex支持库中的MultiDexApplication类添加到应用程序元素中
<?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="androidx.multidex.MultiDexApplication">
<!-- If you are using support libraries use android:name="android.support.multidex.MultiDexApplication" -->
<!--If you are using your own custom Application class then extend -->
<!--MultiDexApplication and change above line as-->
<!--android:name=".YourCustomApplicationClass"> -->
...
</application>
</manifest>
如果您正在使用自己的Application类,请将父类从Application更改为MultiDexApplication。
如果你不能这样做,在你的Application类重写attachBaseContext方法:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
另一种解决方案是尝试使用ProGuard删除未使用的代码-为应用程序配置ProGuard设置以运行ProGuard,并确保您已为发布版本启用收缩。
我一直面临着同样的问题,对于多索引支持,你必须记住你的应用程序的minSdkVersion。如果你使用minSdkVersion 21或以上版本,那么只需要像这样写multiDexEnabled true
defaultConfig {
applicationId *******************
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
它适用于我,如果你使用minSdkVersion低于21(低于棒棒糖),那么你必须做两个额外简单的事情
1. 首先添加这个依赖项
compile’com。android支持:multidex: 1。0。1
在你的房子里,gradle。
2. 最后和第二在清单中添加下面这一行到您的应用程序
android: name = " android.support.multidex.MultiDexApplication "
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name="android.support.multidex.MultiDexApplication"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
宾果,那么它将在较低的版本也工作..:)
快乐的编码
你的方法太多了。dex只能有65536个方法。
正如建议的那样,您可以使用multidex支持。
只需在/build.gradle模块中添加这些行:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1' //with androidx libraries
//implementation 'com.android.support:multidex:1.0.3' //with support libraries
}
或者如果使用module/build.gradle.kts:
android {
// other properties
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled = true
}
...
}
dependencies {
implementation("androidx.multidex:multidex:2.0.1") // with androidx libraries
// implementation("com.android.support:multidex:1.0.3") // with support libraries
}
同样在清单中,将multidex支持库中的MultiDexApplication类添加到应用程序元素中
<?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="androidx.multidex.MultiDexApplication">
<!-- If you are using support libraries use android:name="android.support.multidex.MultiDexApplication" -->
<!--If you are using your own custom Application class then extend -->
<!--MultiDexApplication and change above line as-->
<!--android:name=".YourCustomApplicationClass"> -->
...
</application>
</manifest>
如果您正在使用自己的Application类,请将父类从Application更改为MultiDexApplication。
如果你不能这样做,在你的Application类重写attachBaseContext方法:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
另一种解决方案是尝试使用ProGuard删除未使用的代码-为应用程序配置ProGuard设置以运行ProGuard,并确保您已为发布版本启用收缩。
我得到这个错误消息,因为在编码我的项目自动更新编译版本在我的构建。Gradle文件:
android {
...
buildToolsVersion "23.0.2"
...
}
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' }
通过修正版本来解决:
android {
...
buildToolsVersion "23.0.2"
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}