Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gradle依赖项与Android提供的内部版本冲突_Android_Unit Testing_Android Studio_Android Gradle Plugin_Gradlew - Fatal编程技术网

Android Gradle依赖项与Android提供的内部版本冲突

Android Gradle依赖项与Android提供的内部版本冲突,android,unit-testing,android-studio,android-gradle-plugin,gradlew,Android,Unit Testing,Android Studio,Android Gradle Plugin,Gradlew,可能重复的,尽管解决方案对我没有帮助 我讨厌复制/粘贴所有源代码,但在gradle似乎没有办法:(因为这是gradle在我身边工作的第三天,我把我的代码放在这里,我为放了这么多代码而道歉 我的主项目中有三个项目。因此,我的settings.gradle如下所示: include ':booking-sdk' include ':booking-app-lib' include ':booking-app' buildscript { repositories { jce

可能重复的,尽管解决方案对我没有帮助

我讨厌复制/粘贴所有源代码,但在gradle似乎没有办法:(因为这是gradle在我身边工作的第三天,我把我的代码放在这里,我为放了这么多代码而道歉

我的主项目中有三个项目。因此,我的settings.gradle如下所示:

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
    }
}

ext {
    ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
    CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'

    androidConfiguration = {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }

        packagingOptions {
            exclude 'values/com_crashlytics_export_strings.xml'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'LICENSE.txt'
        }

        lintOptions {
            abortOnError false
            absolutePaths false
            lintConfig file("lint.xml")
        }

        sourceSets {
            main {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src/main/java']
                renderscript.srcDirs = ['src/main/java']
                res.srcDirs = ['src/main/res']
                assets.srcDirs = ['src/main/assets']

                java {
                    exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
                    exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
                }
            }
        }

        signingConfigs {
            debug {
                storeFile file("$rootProject.projectDir/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }

            release {
                storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
                storePassword System.getenv("PASSWORD")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("PASSWORD")
            }
        }
    }
}
-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle
apply plugin: 'com.android.library'

android androidConfiguration

android {
    publishNonDefault true

    productFlavors {
        booking_1 { }

        booking_2 { }
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'org.apache.commons:commons-lang3:3.3.2'

    compile files('src/main/libs/GeoPIP4J.jar')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}
...
:booking-sdk:compileBookingDebugUnitTestJava                 
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
我的主build.gradle(在项目根目录中)如下所示:

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
    }
}

ext {
    ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
    CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'

    androidConfiguration = {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }

        packagingOptions {
            exclude 'values/com_crashlytics_export_strings.xml'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'LICENSE.txt'
        }

        lintOptions {
            abortOnError false
            absolutePaths false
            lintConfig file("lint.xml")
        }

        sourceSets {
            main {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src/main/java']
                renderscript.srcDirs = ['src/main/java']
                res.srcDirs = ['src/main/res']
                assets.srcDirs = ['src/main/assets']

                java {
                    exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
                    exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
                }
            }
        }

        signingConfigs {
            debug {
                storeFile file("$rootProject.projectDir/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }

            release {
                storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
                storePassword System.getenv("PASSWORD")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("PASSWORD")
            }
        }
    }
}
-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle
apply plugin: 'com.android.library'

android androidConfiguration

android {
    publishNonDefault true

    productFlavors {
        booking_1 { }

        booking_2 { }
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'org.apache.commons:commons-lang3:3.3.2'

    compile files('src/main/libs/GeoPIP4J.jar')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}
...
:booking-sdk:compileBookingDebugUnitTestJava                 
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
为了通过机器人分子测试和仪器测试进行单元测试,我正在遵循我测试并成功运行的项目

booking sdk
是保存app业务逻辑的项目,其结构如下:

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
    }
}

ext {
    ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
    CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'

    androidConfiguration = {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }

        packagingOptions {
            exclude 'values/com_crashlytics_export_strings.xml'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'LICENSE.txt'
        }

        lintOptions {
            abortOnError false
            absolutePaths false
            lintConfig file("lint.xml")
        }

        sourceSets {
            main {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src/main/java']
                renderscript.srcDirs = ['src/main/java']
                res.srcDirs = ['src/main/res']
                assets.srcDirs = ['src/main/assets']

                java {
                    exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
                    exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
                }
            }
        }

        signingConfigs {
            debug {
                storeFile file("$rootProject.projectDir/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }

            release {
                storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
                storePassword System.getenv("PASSWORD")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("PASSWORD")
            }
        }
    }
}
-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle
apply plugin: 'com.android.library'

android androidConfiguration

android {
    publishNonDefault true

    productFlavors {
        booking_1 { }

        booking_2 { }
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'org.apache.commons:commons-lang3:3.3.2'

    compile files('src/main/libs/GeoPIP4J.jar')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}
...
:booking-sdk:compileBookingDebugUnitTestJava                 
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
我在
/src/main/java
/src/test/java
下有相同的包名

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
    }
}

ext {
    ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
    CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'

    androidConfiguration = {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }

        packagingOptions {
            exclude 'values/com_crashlytics_export_strings.xml'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'LICENSE.txt'
        }

        lintOptions {
            abortOnError false
            absolutePaths false
            lintConfig file("lint.xml")
        }

        sourceSets {
            main {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src/main/java']
                renderscript.srcDirs = ['src/main/java']
                res.srcDirs = ['src/main/res']
                assets.srcDirs = ['src/main/assets']

                java {
                    exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
                    exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
                }
            }
        }

        signingConfigs {
            debug {
                storeFile file("$rootProject.projectDir/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }

            release {
                storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
                storePassword System.getenv("PASSWORD")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("PASSWORD")
            }
        }
    }
}
-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle
apply plugin: 'com.android.library'

android androidConfiguration

android {
    publishNonDefault true

    productFlavors {
        booking_1 { }

        booking_2 { }
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'org.apache.commons:commons-lang3:3.3.2'

    compile files('src/main/libs/GeoPIP4J.jar')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}
...
:booking-sdk:compileBookingDebugUnitTestJava                 
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
当我运行clean命令时,结果是:

 ./gradlew :booking-sdk:clean
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
:booking-sdk:clean                                                                                       

BUILD SUCCESSFUL

Total time: 4.83 secs
当我运行
/gradlew:passenger sdk:check
代码查看单元测试结果时会发生错误。我首先得到了以上输出,然后出现了很多类似这样的错误:

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
    }
}

ext {
    ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
    CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'

    androidConfiguration = {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }

        packagingOptions {
            exclude 'values/com_crashlytics_export_strings.xml'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'LICENSE.txt'
        }

        lintOptions {
            abortOnError false
            absolutePaths false
            lintConfig file("lint.xml")
        }

        sourceSets {
            main {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src/main/java']
                renderscript.srcDirs = ['src/main/java']
                res.srcDirs = ['src/main/res']
                assets.srcDirs = ['src/main/assets']

                java {
                    exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
                    exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
                }
            }
        }

        signingConfigs {
            debug {
                storeFile file("$rootProject.projectDir/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }

            release {
                storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
                storePassword System.getenv("PASSWORD")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("PASSWORD")
            }
        }
    }
}
-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle
apply plugin: 'com.android.library'

android androidConfiguration

android {
    publishNonDefault true

    productFlavors {
        booking_1 { }

        booking_2 { }
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'org.apache.commons:commons-lang3:3.3.2'

    compile files('src/main/libs/GeoPIP4J.jar')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}
...
:booking-sdk:compileBookingDebugUnitTestJava                 
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
它基本上是说,我的所有导入都不存在,而它们确实存在,并且我的代码文件中没有错误,所有导入都由类识别


如果您有任何想法,我们将不胜感激。谢谢。

好的,Geadel是一个非常可怕的工具,尽管它是一个强大的工具

如果你遇到同样的麻烦,这是我的经验。因为我不确定我的发现是否绝对正确,如果我错了,请纠正我

  • 我发现无法将您的测试文件夹放在库项目下。我希望每个项目库都有
    src/test/java
    ,并运行我的测试用例,如
    /gradlew:booking sdk:test
    。但是,通过将此包移动到主应用程序(在我的情况下是
    booking app
    )还可以将相关文件从
    预订sdk的build.gradle移动到
    预订应用程序的build.gradle,我可以看到测试用例结果
  • 我发现
    exclude
    模块不工作。我发现的解决方案是使用配置
像这样:

configurations {
    all*.exclude module: 'classworlds'
    all*.exclude module: 'commons-logging'
    all*.exclude module: 'httpclient'
    all*.exclude module: 'maven-artifact'
    all*.exclude module: 'maven-artifact-manager'
    all*.exclude module: 'maven-error-diagnostics'
    all*.exclude module: 'maven-model'
    all*.exclude module: 'maven-project'
    all*.exclude module: 'maven-settings'
    all*.exclude module: 'plexus-container-default'
    all*.exclude module: 'plexus-interpolation'
    all*.exclude module: 'plexus-utils'
    all*.exclude module: 'wagon-file'
    all*.exclude module: 'wagon-http-lightweight'
    all*.exclude module: 'wagon-provider-api'
}

希望有帮助。

如果您想知道如何查找和排除依赖项,请查看