当我在android studio项目中添加fire base analytics时出现以下错误: "错误:将字节码转换为dex时出错: 原因:com.android.dex.DexException:多个dex文件定义Lcom / google / android / gms / measurement / AppMeasurementContentProvider;"
如果有人告诉我额外的AppmeasurementContentProvider来自哪里以及相应的"排除"我真的很感激。命令。
这是我的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
exclude 'com.google.android.gms.measurement'
}
defaultConfig {
applicationId "com.elisiumlabs.sarthi"
minSdkVersion 10
targetSdkVersion 19
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile project(':androidQuery')
compile project(':pinnedSectionListActivity')
compile project(':volley')
compile project(':facebookSDK')
compile 'com.google.code.gson:gson:2.2.4'
compile 'joda-time:joda-time:2.3'
compile 'com.android.support:gridlayout-v7:21.0.0'
compile "com.google.android.gms:play-services-location:8.3.0"
// compile "com.google.android.gms:play-services-gcm:8.3.0"
compile 'com.android.support:appcompat-v7:21.0.3'
compile('com.google.android.gms:play-services-gcm:8.3.0') {
exclude group: 'com.google.android.gms.measurement'
}
compile('com.google.firebase:firebase-core:9.0.2')
{
exclude group: 'com.google.android.gms.measurement'
}
/*compile files('libs/appcompat_v7.jar')*/
compile files('libs/commons-io-1.4.jar')
compile files('libs/commons-lang-2.4.jar')
compile files('libs/httpclient-4.3.5.jar')
/*compile files('libs/objectify-5.0.3.jar')*/
compile 'commons-codec:commons-codec:1.9'
compile files('libs/splunk-mint-4.1.jar')
testCompile 'junit:junit:4.12'
// androidTestCompile 'com.android.support:support-annotations:21.0.0'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
/* androidTestCompile('com.android.support.test.espresso:espresso- core:2.2.1') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}*/
androidTestCompile('com.android.support.test.espresso:espresso- contrib:2.2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'javax.inject'
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2'){
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
// Optional -- UI testing with UI Automator
androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.1'){
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
答案 0 :(得分:0)
使用Gradle为Multidex配置应用程序 参考https://developer.android.com/studio/build/multidex.html#mdex-gradle
修改模块级build.gradle文件配置以包含支持库并启用multidex输出,如以下代码段所示:
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'
}
扩展Application类,可以覆盖attachBaseContext()方法并调用MultiDex.install(this)来启用multidex。有关更多信息,请参阅MultiDexApplication参考文档。
答案 1 :(得分:0)
尝试我的回答......
这是链接
Android Studio Gradle Error:Execution failed for task ':app:dexDebug' using Ion koush lib
请将Google服务作为我的答案,并将一些代码添加到您的gradle,如图所示,还在您最主要的文件中添加一些代码
并且如同回答
中所示,使用comdex multidexenable也是如此首先使用
编译构建compile' com.android.support:multidex:1.0.1'
compile' com.google.android.gms:play-services:+'
在 AndroidManifest.xml 中添加以下行 android:name
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
在 build.gradle 中也添加
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
答案 2 :(得分:0)
我真的认为你不能混用GCM和FCM,因为FCM是新的GCM。从逻辑上讲,他们必须分享几乎相似的api来进行互通。
您应该选择FCM或GCM。从你的build.gradles看起来你使用gcm。因此,删除FCM代码。删除这些行:
$re = '/(?<=^|\.jpg)\w+\.jpg/m';
preg_match_all($re, $input, $matches);
print_r($matches[0]);
在Setting Up Google Play Services阅读GCM的播放服务设置 和FCM在Add Firebase to your Android Project。
答案 3 :(得分:0)
当我尝试且版本级别不匹配时,Android Studio会发出以下警告:
请通过更新google-services插件的版本来修复版本冲突(有关最新版本的信息,请访问https://bintray.com/android/android-tools/com.google.gms.google-services/)
因此,设置为相同的版本级别可以解决彼此不兼容的依赖关系
compile('com.google.android.gms:play-services-gcm:11.8.0')
compile('com.google.firebase:firebase-core:11.8.0')