Android Studio无法解决gradle依赖关系

时间:2015-09-22 14:31:30

标签: android maven android-studio gradle android-gradle

我在android studio中创建了以下App。在运行时,我收到以下发布的错误。我检查了build.gradle文件,但我不知道什么 错了。

问题是android studio在R.layout发出错误并说:无法解析符号R

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_main);
    }
}

gradle.build

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.com.bt_11"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.+'
}

错误

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.android.support:appcompat-v7:23.+.
 Required by:
     BT_11:app:unspecified
  > Could not resolve com.android.support:appcompat-v7:23.+.
     > Failed to list versions for com.android.support:appcompat-v7.
        > Unable to load Maven meta-data from https://jcenter.bintray.com/com/android/support/appcompat-v7/maven-metadata.xml.
           > Could not GET 'https://jcenter.bintray.com/com/android/support/appcompat-v7/maven-metadata.xml'.
              > Connection to https://jcenter.bintray.com refused

更新: 我将compileSdkVersion,targetSdkVersion设置为23,minSdkVersion = 19

现在我在尝试运行App时遇到了以下错误:

2 个答案:

答案 0 :(得分:1)

update your Android SDK Manager and after that rebuild your android studio 
project.

答案 1 :(得分:0)

首先更新您的 SDK MANAGER 它应该解决gradle无法解决com.android.support:appcompat-v7:23.+.

的问题

enter image description here

然后在build.gradle中,您必须更改compileSdkVersion appcompat v23 需要 compileSdkVersion 23