2016-11-15 32 views
0

項目級別Gradle文件:頂級構建文件,您可以在其中添加對所有子項目/模塊通用的配置選項。在Android Studio中創建新項目時無法解析符號appCompatActivity?

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.2' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

模塊級gradle這個:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 
    defaultConfig { 
     applicationId "in.co.persistent.gamedisappear" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.0.1' 
    testCompile 'junit:junit:4.12' 
} 

` The error I get我知道這個問題被問了許多times.But我已經試過各種事情像無效/重啓cache.Also試圖重新啓動Android和建設新項目.Plus添加了所需的依賴項(compile'c​​om.android.support:appcompat-v7:25.0.1')沒有任何作用!

+1

請發佈您的錯誤代碼和gradle屬性爲您的應用程序:) –

+0

我附上了我得到的錯誤圖像! – Delfin

+0

你會發布你的build.gradle文件嗎? – TheAnonymous010

回答

1

從gradle這個生成錯誤截圖很顯然,問題是再也決心的junit:junit的4.12
解決方案 -如果您不需要運行單元測試用例,然後你評論下面一行testCompile 'junit:junit:4.12'和檢查
但如果你需要根據問題的意見提出的模塊級的build.gradle文件它,那麼請添加以下代碼

repositories { 
     jcenter() 
     maven { url 'http://repo1.maven.org/maven2' } 
    } 

編輯 -原因。
爲什麼我們會得到錯誤?有時可能會發生這樣的情況,即在存儲庫中可能不存在所需的依賴項/已用版本/路徑已更改。欲瞭解更多信息,您需要了解gradle如何工作

+0

是的我做了同樣的工作,但它爲什麼工作,但他們爲什麼錯誤畢竟只是依賴關係。 – Delfin

0

我在build.gradle中將我的依賴關係更改爲下面,它工作...雖然不知道背後的原因。

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

也許你需要添加'com.android.support:support-compat:25.0。1'到你以前的依賴關係。因爲在[documentation](https://developer.android.com/topic/libraries/support-library/features.html)中,它說「這個庫依賴於v4支持庫。」 –

相關問題