3

この質問の重複の可能性がありますが、解決策は役に立ちませんでした。

私はすべてのソースコードをコピー/貼り付けするのは嫌いですが、gradleには方法がないようです:(これはgradleが私にスタッフを配置してから3日目なので、コードをここに置き、非常に多くのコードを入れたことをお詫びします...

メインプロジェクトに 3 つのプロジェクトがあります。したがって、私の settings.gradle は次のようになります。

include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'

私のメインのbuild.gradle(プロジェクトのルートにある)は次のようになります。

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")
            }
        }
    }
}

Robolectric および Instrument テストによる単体テストを行うために、私はテストして正常に動作する Decard -Gradleプロジェクトに従っています。

booking-sdkアプリのビジネスロジックを保持するプロジェクトです。その構造は次のようになります。

-booking-sdk
-/build
-/src
  - booking_1 (flavour 1)
  - booking_2 (flavour 2)
  - main
  - test
- build.gradle

と の下に同じパッケージ名が/src/main/javaあり/src/test/javaます。最後に、 build.gradle はbooking-sdk次のようになります。

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'
    }
}

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コードを実行して単体テストの結果を確認すると、エラーが発生します。最初に出力を超えてから、次のような多くのエラーが発生します。

...
: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;

基本的に、すべてのインポートが存在するのに存在しないと言っており、コードファイルとクラスによって認識されるすべてのインポートにエラーはありません。

任意のアイデアをいただければ幸いです。ありがとう。

4

1 に答える 1