我在项目中添加了一个模块File-> New-> Import Module。 app目录中存在冲突,所以我在我的模块中命名odkapp而不是app,然后导入。在此之后,我能够成功同步项目。
现在我在我的应用中添加依赖项 - >实现项目(':odkapp')并开始同步,它给出了以下错误:
无法解决项目:odkapp。要求: 项目:app
无法找到项目的匹配配置:odkapp: - 配置'debugApiElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',找到兼容的值'debug'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'Apk'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'debug'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api'并找到兼容的值'java-api'。 - 配置'debugMetadataElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',找到兼容的值'debug'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'元数据'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'debug'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api'但没有提供任何值。 - 配置'debugRuntimeElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',找到兼容的值'debug'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'Apk'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'debug'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api',发现不兼容的值'java-runtime'。 - 配置'releaseApiElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',发现不兼容的值'release'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'Apk'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'release'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api'并找到兼容的值'java-api'。 - 配置'releaseMetadataElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',发现不兼容的值'release'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'元数据'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'release'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api'但没有提供任何值。 - 配置'releaseRuntimeElements': - 必需的com.android.build.api.attributes.BuildTypeAttr'debug',发现不兼容的值'release'。 - 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和 发现不兼容的价值'Apk'。 - 找到com.android.build.gradle.internal.dependency.VariantAttr'release'但是 不是必需的。 - 必需的org.gradle.api.attributes.Usage'java-api',发现不兼容的值'java-runtime'。
以下是我的项目级别gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
以下是app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.odk.collect.custom.mapit.myapplication"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation project (':odkapp')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
下面是模块(odkapp)gradle:
apply plugin: 'com.android.application'
apply plugin: 'jacoco-android'
apply from: '../config/quality.gradle'
import com.android.ddmlib.DdmPreferences
DdmPreferences.setTimeOut(60000)
ant.condition(property: 'os', value: 'windows') {
os(family: 'windows')
}
ant.condition(property: 'os', value: 'unix') {
os(family: 'unix')
}
// Build numbers were manually set until 1067
def LEGACY_BUILD_NUMBER_OFFSET = 1067
// Based on http://stackoverflow.com/questions/17097263#24121734
def getMasterCommitCount = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'rev-list', '--first-parent', '--count', 'master'
break
case 'unix':
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
break
}
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
} catch (ignored) {
return -1;
}
}
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'describe', '--tags', '--dirty', '--always'
break
case 'unix':
commandLine 'git', 'describe', '--tags', '--dirty', '--always'
break
}
standardOutput = stdout
}
return stdout.toString().trim()
} catch (ignored) {
return null;
}
}
def secretsFile = file('secrets.properties')
def secrets = new Properties()
if (secretsFile.exists()) {
secrets.load(new FileInputStream(secretsFile))
}
android {
compileSdkVersion(26)
buildToolsVersion '26.0.2'
defaultConfig {
applicationId('com.odk.collect.custom.mapit')
minSdkVersion(16)
targetSdkVersion(22)
versionCode LEGACY_BUILD_NUMBER_OFFSET + getMasterCommitCount()
versionName getVersionName()
testInstrumentationRunner('android.support.test.runner.AndroidJUnitRunner')
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
release {
if (secrets.getProperty('RELEASE_STORE_FILE')) {
storeFile file(secrets.getProperty('RELEASE_STORE_FILE'))
storePassword secrets.getProperty('RELEASE_STORE_PASSWORD')
keyAlias secrets.getProperty('RELEASE_KEY_ALIAS')
keyPassword secrets.getProperty('RELEASE_KEY_PASSWORD')
}
}
}
buildTypes {
release {
if (secrets.getProperty('RELEASE_STORE_FILE')) {
signingConfig signingConfigs.release
}
minifyEnabled(true)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable(true)
// Allows AndroidTest JaCoCo reports to be generated
testCoverageEnabled(true)
}
}
// https://stackoverflow.com/a/27119543/152938
applicationVariants.all { variant ->
variant.outputs.all { output ->
def file = output.outputFileName
// output.outputFileName = new File(file.parent, file.name.replace("_app","").replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
packagingOptions {
// Pick first occurrence of any files that cause conflicts, as defined
// in common.gradle
pickFirst 'META-INF/DEPENDENCIES'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/LICENSE.txt'
pickFirst 'META-INF/NOTICE'
pickFirst 'META-INF/NOTICE.txt'
pickFirst 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
pickFirst 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyReader'
pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyWriter'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
javaMaxHeapSize '2048M'
}
}
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(0, 'seconds')
cacheChangingModulesFor(0, 'seconds')
}
transitive = true
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all'
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: '*.jar')
compile group: 'com.android.support', name: 'appcompat-v7', version: '26.0.2'
compile group: 'com.android.support', name: 'design', version: '26.0.2'
compile group: 'com.android.support', name: 'cardview-v7', version: '26.0.2'
compile group: 'com.android.support', name: 'multidex', version: '1.0.1'
compile group: 'com.google.android.gms', name: 'play-services-analytics', version: '10.0.1'
compile group: 'com.google.android.gms', name: 'play-services-auth', version: '10.0.1'
compile group: 'com.google.android.gms', name: 'play-services-maps', version: '10.0.1'
compile group: 'com.google.android.gms', name: 'play-services-location', version: '10.0.1'
compile(group: 'com.google.code.gson', name: 'gson', version: '2.6.2') {
exclude group: 'org.apache.httpcomponents'
}
compile group: 'com.google.firebase', name: 'firebase-core', version: '10.0.1'
compile group: 'com.google.firebase', name: 'firebase-crash', version: '10.0.1'
compile(group: 'com.google.http-client', name: 'google-http-client', version: '1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile(group: 'com.google.oauth-client', name: 'google-oauth-client', version: '1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'joda-time', name: 'joda-time', version: '2.9.7'
compile group: 'net.sf.kxml', name: 'kxml2', version: '2.3.0'
compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.3'
compile group: 'org.opendatakit', name: 'opendatakit-javarosa', version: '2.5.1'
compile group: 'org.osmdroid', name: 'osmdroid-android', version: '5.6.4'
compile group: 'org.slf4j', name: 'slf4j-android', version: '1.6.1-RC1'
compile group: 'pub.devrel', name: 'easypermissions', version: '0.2.1'
compile(group: 'com.google.api-client', name: 'google-api-client-android', version: '1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile(group: 'com.google.apis', name: 'google-api-services-drive', version: 'v3-rev64-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile(group: 'com.google.apis', name: 'google-api-services-sheets', version: 'v4-rev463-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile group: 'com.jakewharton.timber', name: 'timber', version: '4.5.1'
compile group: 'com.android.support', name: 'customtabs', version: '26.0.2'
compile group: 'com.android.support', name: 'design', version: '26.0.2'
compile group: 'com.google.zxing', name: 'core', version: '3.3.0'
compile group: 'com.journeyapps', name: 'zxing-android-embedded', version: '3.5.0'
compile group: 'com.android.support', name: 'support-v13', version: '26.0.2'
//Start : Added by Araju
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
//End : Added by Araju
// Testing-only dependencies
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.8.47'
testCompile group: 'org.robolectric', name: 'robolectric', version: '3.4'
testCompile group: 'org.robolectric', name: 'shadows-multidex', version: '3.3.2'
androidTestCompile group: 'com.android.support', name: 'support-annotations', version: '26.0.2'
androidTestCompile group: 'com.android.support.test', name: 'runner', version: '0.5'
androidTestCompile group: 'com.android.support.test', name: 'rules', version: '0.5'
androidTestCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.2.0'
}
// Must be at bottom to prevent dependency collisions
// https://developers.google.com/android/guides/google-services-plugin
apply plugin: 'com.google.gms.google-services'
有人可以帮我吗?