编译错误;为什么我的产品风格无法解析已导入/ main的依赖项?

时间:2019-01-08 02:09:15

标签: java android gradle build.gradle android-productflavors

我继承了一个维护不佳/未提供文档的android应用程序,我需要添加一个简单的产品样式以允许在我们的应用程序中进行版本控制,特别是,一个不跟踪位置的版本以及一个可以跟踪位置的版本(例如我们的应用程序已经完成了。)

这是我项目的文件结构: enter image description here

我已按照Android开发文档的指示将产品口味添加到我的应用程序build.gradle文件中。这是应用程序级别的build.gradle文件:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
    flavorDimensions "version"
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName version
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        nonLocationTracking {
            dimension "version"
            minSdkVersion 14
            targetSdkVersion 27
            versionCode 1
            manifestPlaceholders = [appName: "@string/app_name_non_location"]
        }
        locationTracking {
            dimension "version"
            minSdkVersion 14
            targetSdkVersion 27
            versionCode 1
            manifestPlaceholders = [appName: "@string/app_name_location"]
        }
    }

    lintOptions {
        abortOnError false
    }

    publishNonDefault true
}

configurations {
    javadocDeps
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
}

publish {
    userOrg = '****'
    groupId = 'com.****.android'
    artifactId = '****'
    publishVersion = '2.0.0'
    desc = 'survata sdk'
    website = 'https://github.com/****/****-android-public-sdk'
}

这样做之后,我收到此编译错误:

org.gradle.initialization.ReportedException: 
org.gradle.internal.exceptions.LocationAwareException: Execution failed for 
task ':survata-sample:compileDebugJavaWithJavac'

之后是此堆栈跟踪,它指向无法解决的导入依赖关系:

/Users/alexg/git/****-android-public-sdk    
****-sample/src/main/java   
com/****/demo/ui/SurveyDebugOption.java 
error: cannot find symbol class Survey  
error: cannot find symbol class SurveyOption    
error: cannot find symbol variable super    
error: method does not override or implement a method from a supertype  
com/survata/demo/ui/DemoFragment.java   
error: cannot find symbol class Survey  
error: cannot find symbol class Survey  
error: cannot find symbol class SurveyOption    
error: cannot find symbol class Survey  
error: package Survey does not exist    

此sdk(上面的build.gradle的来源)已加载到示例应用程序中,该应用程序也存在于此项目文件夹中,如上面的文件结构屏幕快照所示。具体的问题是,在上述sdk的build.gradle中创建了产品风味之后,示例应用程序将无法再解析来自导入的sdk的导入的依赖项。

这是示例应用程序的build.gradle文件:

apply plugin: 'com.android.application'

def computeVersionCode = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-list', 'HEAD', '--count'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger();
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.****.demo"
        minSdkVersion 15
        targetSdkVersion 27

        versionCode computeVersionCode()
        versionName "1.0"

        renderscriptTargetApi 20
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    signingConfigs {
        debugConfig {
            storeFile file("debug.jks")
            storePassword "****"
            keyAlias "com.****.android"
            keyPassword "****"
        }

        releaseConfig {
            storeFile file("release.jks")
            storePassword "****"
            keyAlias "com.****.android"
            keyPassword "****"
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debugConfig
        }
        release {
            signingConfig signingConfigs.releaseConfig
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:preference-v7:27.1.1'
    implementation 'com.google.guava:guava:23.0'
    implementation 'com.squareup:seismic:1.0.2'
    implementation 'net.hockeyapp.android:HockeySDK:3.7.0'
    implementation 'jp.wasabeef:blurry:1.0.5'

    implementation project(path: ':****-sdk', configuration: 'default')
    testImplementation 'junit:junit:4.12'
}

给我的印象是/ main中的文件可以被任何不覆盖该代码的产品使用。我对此有错吗?谁能告诉我我在这里做错了什么以及如何配置我的产品风格,以便他们利用/ main中的依赖项?

*注意:将我的组织名称换成****

0 个答案:

没有答案