Android gradle build and the support library

后端 未结 5 882
梦毁少年i
梦毁少年i 2020-12-14 06:27

I have a project that uses a few other library projects (SlidingMenu, ActionbarSherlock) and both of these use the android support library, when building I am getting the fo

相关标签:
5条回答
  • 2020-12-14 06:41

    The ADT will throw an exception like UNEXPECTED TOP-LEVEL EXCEPTION if your Eclipse classpath contains more than one class of the same name/package/jars. In this case it is encountering more than one instance of the LoaderManager class.

    Solution : You have same jar library included twice. Check your application and all referenced Android libraries and make sure you have all jars included exactly once.

    0 讨论(0)
  • 2020-12-14 06:51

    Based in the answer from Xav, if you have other modules that depends on android-support-v4.jar, create a library project which contains the android-support-v4.jar and reference this project instead the jar file.

    E.g.:

    Add a project with this structure:

    - android-support
      - libs
        - android-support-v4.jar
      - AndroidManifest.xml
      - build.gradle
    

    AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.example.support.lib">
    
        <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7"/>
    
    <application />
    
    </manifest>
    

    build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
        }
    }
    apply plugin: 'android-library'
    
    dependencies {
        compile files ("libs/android-support-v4.jar")
    
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "17"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 7
        }
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
            }
    
        }
    }
    

    remember to include this project in your projects settings.gradle:

    include  ':android-support'
    

    now, for each project that requires the support library, instead of

    compile files ("libs/android-support-v4.jar")
    

    use the following line:

    compile project (':android-support')
    
    0 讨论(0)
  • 2020-12-14 06:51

    FYI, I had to add this to exclude the android-support-v4.jar in my gradle build because I added it as an artifact:

    compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-v4.jar')

    I created the build.gradle using the project export feature in Eclipse's ADT plugin.

    0 讨论(0)
  • 2020-12-14 07:02

    This is now possible by downloading Android Support Repository from the SDK Manager, and replacing

    compile files("libs/android-support-v4.jar")
    

    with

    compile 'com.android.support:support-v4:13.0.0'
    

    This has to be done for all projects that use the support library. The Android Support Repository is automatically added to your list of repositories by the build system (Unsure of which part adds it, don't know enough gradle yet).

    Source

    0 讨论(0)
  • 2020-12-14 07:05

    Until we have the support library has a repository artifact you cannot include it in more than one library project. You could create a library project that only contains the support library, and have all other libraries depend on it.

    Update: this is now possible.

    0 讨论(0)
提交回复
热议问题