当我将链接的库集成到我的android项目中时出现多桌错误

时间:2017-10-24 05:37:26

标签: android linkedin linkedin-api

我收到错误

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 

我在sdk中成功添加链接但是当我编译项目(':linkedin-sdk')然后给我错误我试图解决此错误我也尝试multiDexEnabled true但仍然得到错误这是我的app.gradle文件

   buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

    android {
        compileSdkVersion 26
        buildToolsVersion '26.0.2'
        defaultConfig {
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true

        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }

        }

    }

    repositories {
        maven { url 'http://developers.quikkly.io/nexus/repository/maven-releases/' }
        maven { url 'http://developers.quikkly.io/nexus/repository/maven-snapshots/' }
        maven { url 'https://maven.fabric.io/public' }
        mavenLocal()
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.android.support:design:25.3.1'
        compile 'com.android.volley:volley:1.0.0'
        compile 'com.facebook.android:facebook-android-sdk:4.27.0'
        compile 'com.intuit.sdp:sdp-android:1.0.4'
        compile 'com.squareup.picasso:picasso:2.5.2'
        testCompile 'junit:junit:4.12'
        compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
        compile 'com.brucetoo.pickview:library:1.2.3'
        compile 'com.caverock:androidsvg:1.2.1'
        compile 'commons-io:commons-io:2.5'

        // Pretty color picker
        compile('com.thebluealliance:spectrum:0.7.1') {
            // spectrum uses older support libs, override these with latest.
            exclude group: 'com.android.support'
        }
        compile('net.quikkly.android:quikklycore-lib:1.2.0@aar') {
            transitive = true
        }
        compile 'net.quikkly.android:quikkly-lib:1.2.0@aar'
        compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
            transitive = true;
        }
        // Include all the Twitter APIs
        compile 'com.twitter.sdk.android:twitter:3.1.1'
        // (Optional) Monetize using mopub
        compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
        implementation 'com.android.support:support-v13:26.1.0'
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:support-v4:26.1.0'
        implementation 'com.android.support:support-vector-drawable:26.1.0'

    }

这是我的linkedin gradle文件

allprojects {
    repositories {
        mavenCentral()
    }
}

buildscript {
   repositories {
     mavenCentral()
   }

}

apply plugin: 'android-library'

android {
    sourceSets {
        androidTest {
          setRoot('src/test')
        }
    }
    compileSdkVersion 17 
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16 
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
          abortOnError false
    }
}

configurations {
}


dependencies {
    compile 'com.android.support:support-annotations:20.0.0'
    compile 'com.android.support:support-v4:21.0.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/volley.jar')
    androidTestCompile('junit:junit:4.12')
}

如果有任何帮助或建议,我使用android studio 3.0 RC 2与cannery请让我知道谢谢你的进展
编辑:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

3 个答案:

答案 0 :(得分:0)

在您的linkedin gradle文件中使用它:

allprojects
{
    repositories
    {
        maven
        {
            url "https://maven.google.com"
        }
    }
}

答案 1 :(得分:0)

android {
    defaultConfig {
       multiDexEnabled true
    }
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

public class ApplicationClass extends MultiDexApplication {
 @Override
    public void onCreate() {
        super.onCreate();
    }
}

答案 2 :(得分:0)

我正在提供完整的MultidexApplication代码

app gradle

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

如果您覆盖Application类,请将其更改为扩展MultiDexApplication(如果可能),如下所示:

public class MyApplication extends MultiDexApplication { ... }

或者,如果您覆盖Application类但无法更改基类,则可以覆盖attachBaseContext()方法并调用MultiDex.install(this)以启用multidex:

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}
  

警告:在MultiDex.install()完成之前,不要通过反射或JNI执行MultiDex.install()或任何其他代码。 Multidex跟踪不会跟随这些调用,导致ClassNotFoundException或验证由于DEX文件之间的类分区错误而导致的错误。