无法解决:com.android和gradle项目同步失败

时间:2018-09-24 17:46:49

标签: android kotlin

当我在“依赖项”部分中添加以下行时

implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"

我遇到两个错误:

  

无法解决:com.android;

     

Gradle项目同步失败。基本功能(例如,编辑,调试)将无法正常工作。

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.raywenderlich.isell"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  androidExtensions {
    experimental = true
  }
}

dependencies {
  // Kotlin
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
  // AppCompat
  implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
  // Design Support Library
  implementation "com.android.support:design:$supportLibraryVersion"
  // CardView
  implementation "com.android.support:cardview-v7:$supportLibraryVersion"
}

如何解决这些问题?

1 个答案:

答案 0 :(得分:0)

替换为以下代码,并为每个 kotlinVersion,supportLibraryVersion

提供适当的版本
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

    ext {
        kotlinVersion = ""
        supportLibraryVersion = ""
    }

android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.raywenderlich.isell"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  androidExtensions {
    experimental = true
  }
}

dependencies {
  // Kotlin
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
  // AppCompat
  implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
  // Design Support Library
  implementation "com.android.support:design:$supportLibraryVersion"
  // CardView
  implementation "com.android.support:cardview-v7:$supportLibraryVersion"
}

希望这会对您有所帮助。