Android

时间:2015-06-21 11:27:31

标签: android android-studio android-gradle

我目前正在Android Studio中开发 Android 应用程序。我已经向应用程序导入了两个模块。下面的列表显示了项目的结构以及我在应用程序中的模块:

  1. Project Gradle(youtubeapplication)
  2. 模块#1 Gradle(YT SDK字符串库)
  3. App Gradle(app)
  4. 模块#2 Gradle(vIMEOSDKStringLibrary)
  5. 当我尝试运行应用程序时,我得到了以下消息gradle build,这显然显示了一个"意外的顶级"例外:

      

    输出:         意外的顶级例外情况:         com.android.dex.DexException:多个dex文件定义LA $ 1;             在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)             在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)             在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)             在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)             在com.android.dx.merge.DexMerger.merge(DexMerger.java:189)             在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)             在com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)             在com.android.dx.command.dexer.Main.run(Main.java:246)             在com.android.dx.command.dexer.Main.main(Main.java:215)             在com.android.dx.command.Main.main(Main.java:106)

    我已经阅读过该例外情况。而且它是由重复版本的库引起的,我试图检查项目的gradle文件但是无法修复它。我将逐个列出gradle文件:

    1) Project Gradle(youtubeapplication)

    
    
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.0.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    
    

    2)模块#1 Gradle(YT SDK字符串库)

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile files('libs/jsoup-1.7.3.jar')
        compile files('libs/mobilecore.jar')
        compile files('libs/vimeo_m_1_0_0_1.jar')
    }
    

    3) App Gradle(app)

    
    
    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion '21.1.2'
        defaultConfig {
            applicationId "com.me.thats.youtubeappliction"
            minSdkVersion 15
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:22.+'
    
        compile 'com.melnykov:floatingactionbutton:1.2.0'
        compile 'com.squareup.picasso:picasso:2.5.2'
        compile project(':YT SDK String Library')
        compile project(':vIMEOSDKStringLibrary')
    
    }
    
    
    

    4)模块#2 Gradle(vIMEOSDKStringLibrary)

    
    
    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 20
        buildToolsVersion "19.1.0"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile files('libs/jsoup-1.7.3.jar')
        compile files('libs/mobilecore.jar')
        compile files('libs/vimeo_m_1_0_0_1.jar')
    }
    
    
    

    =======================

    编辑:

    我刚刚运行了Gradle命令":app:androidDependencies"获取项目的依赖项树。有人可以告诉我是否有关于Gradle命令输出的事情":app:androidDependencies"

        10:52:36 PM: Executing external task ':app:androidDependencies'...
    :app:androidDependencies
    debug
    +--- LOCAL: YouTubeAndroidPlayerApi.jar
    +--- com.android.support:appcompat-v7:22.1.1
    |    \--- com.android.support:support-v4:22.1.1
    |         \--- LOCAL: internal_impl-22.1.1.jar
    +--- com.melnykov:floatingactionbutton:1.2.0
    |    \--- com.android.support:recyclerview-v7:21.0.2
    |         \--- com.android.support:support-v4:22.1.1
    |              \--- LOCAL: internal_impl-22.1.1.jar
    +--- youtubeappliction:YT SDK String Library:unspecified
    |    \--- LOCAL: ytsdk_4_0_M.jar
    \--- youtubeappliction:vIMEOSDKStringLibrary:unspecified
         +--- LOCAL: jsoup-1.7.3.jar
         +--- LOCAL: mobilecore.jar
         \--- LOCAL: vimeo_m_1_0_0_1.jar
    
    debugTest
    No dependencies
    
    release
    +--- LOCAL: YouTubeAndroidPlayerApi.jar
    +--- com.android.support:appcompat-v7:22.1.1
    |    \--- com.android.support:support-v4:22.1.1
    |         \--- LOCAL: internal_impl-22.1.1.jar
    +--- com.melnykov:floatingactionbutton:1.2.0
    |    \--- com.android.support:recyclerview-v7:21.0.2
    |         \--- com.android.support:support-v4:22.1.1
    |              \--- LOCAL: internal_impl-22.1.1.jar
    +--- youtubeappliction:YT SDK String Library:unspecified
    |    \--- LOCAL: ytsdk_4_0_M.jar
    \--- youtubeappliction:vIMEOSDKStringLibrary:unspecified
         +--- LOCAL: jsoup-1.7.3.jar
         +--- LOCAL: mobilecore.jar
         \--- LOCAL: vimeo_m_1_0_0_1.jar
    
    BUILD SUCCESSFUL
    
    Total time: 3.448 secs
    10:52:40 PM: External task execution finished ':app:androidDependencies'.
    

    注意:导入模块#2时会出现此问题。当我删除它时,一切都很顺利。

    提前致谢

2 个答案:

答案 0 :(得分:0)

至于我,在您的依赖项中,您拥有相同的不同版本的库 1)运行Gradle :app:dependencies以查看项目的依赖关系树和每个模块
2)检查依赖项列表并找到重复的库,检查它们的版本
3)如果您找到了一些不同版本的库,请更新依赖关系以确保您在项目的任何位置拥有相同版本的库。

我刚刚发现您在模块2中有以下构建配置 compileSdkVersion 20 buildToolsVersion "19.1.0"

尝试将其更改为第1单元配置:

compileSdkVersion 22 buildToolsVersion "21.1.2"

答案 1 :(得分:0)

重新安排最近的android studio插件并重新安装它们在大多数情况下都适用