这个问题在这里已有答案:
每当我尝试重新构建或运行我的代码时,都会出现以下错误:错误:任务执行失败':app:transformDexArchiveWithExternalLibsDexMergerForDebug'。
java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
我检查了很多解决方案但没有解决它。以下是链接。 Unable to Merge Dex - Android Studio 3.0
使用堆栈树运行gradle控制台有4个错误:
使用debug-option运行了:
错误:10:49:47.799 [错误] [system.err]注意:某些输入文件使用或覆盖已弃用的API。 10:49:47.799 [错误] [system.err]注意:使用-Xlint重新编译:弃用以获取详细信息。 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]失败:构建因异常而失败。 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *出了什么问题:10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]> com.android.builder.dexing.DexArchiveMergerException:无法合并dex 10:50:01.875 [错误] [org.gradle.internal.buildevents .BuildExceptionReporter] 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *尝试:10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]使用--stacktrace选项运行获得堆栈跟踪。 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *在https://help.gradle.org 10:50:01.875获取更多帮助[ ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 10:50:01.875 [错误] [org.gradle.internal.buildevents.BuildResultLogger]在1m 7s内建立失败
请帮助我使用Firebase制作聊天应用程序。我被困在这里2天,我无法继续下去。
我的(build.gradle)文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.imalok.saapchat"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.firebaseui:firebase-ui-database:2.3.0'
implementation 'id.zelory:compressor:2.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.firebase:firebase-storage:11.0.4'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imalok.saapchat">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
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>
<activity android:name=".StartActivity" />
<activity
android:name=".RegisterActivity"
android:parentActivityName=".StartActivity" />
<activity
android:name=".LoginActivity"
android:parentActivityName=".StartActivity" />
<activity android:name=".SettingsActivity" />
<activity
android:name=".StatusActivity"
android:parentActivityName=".SettingsActivity" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity
android:name=".UsersActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".ProfileActivity"></activity>
</application>
编辑:1你们会删除重复级别吗?矿井问题不同,正如我发布的那样,解决方案也是如此。
转换dex合并问题是持久的..直到我添加了依赖::
implementation 'android.arch.lifecycle:extensions:1.1.0'
你已经启用了multidex:
multiDexEnabled true
但你没有使用multidex库。 将multidex库添加到依赖项:
implementation 'com.android.support:multidex:1.0.3'
在您的Application类中:
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
更多参考这个问题:
How to enable multidexing with the new Android Multidex support library
你可以使用dexOptions
。
android{
dexOptions {
javaMaxHeapSize "4g"
}
}
将它放在app的build.gradle文件中。将dexOptions放在build.gradle文件的android块中
在您的应用程序gradle文件中添加以下依赖项,因为您在gradle中提到了multiDexEnabled true
。
implementation 'com.android.support:multidex:1.0.3'
之后
通过MultiDexApplication扩展您的应用程序类
然后保留您在应用程序类中的旧代码
并在您的应用程序gradle文件中提及以下术语。
android {
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}