8

當我在PC上工作時,我已經成功構建了一個項目,並在遷移到OSX之前將其提交到我的Git倉庫。OS Studio上的舊版和新版Gradle構建失敗

現在,我在OSX上安裝了Android Studio最新版本,並嘗試構建相同的項目,並在構建資源時出現錯誤。雖然在清單建設資源,它提供了多種的錯誤,說

沒有資源發現在給定的名字

爲可繪製和字符串相匹配。

在瀏覽網頁時,我想也許更新版本的gradle有一些問題。所以,我將AS的安裝降級到AS 1.0,並使用舊的gradle 2.2。不幸的是,這個版本的gradle也給出了同樣的錯誤。

build.gradle看起來象下面這樣:

apply plugin: 'com.android.application' 
android { 
compileSdkVersion 21 
buildToolsVersion "21.1.2" 

defaultConfig { 
    applicationId "xxx" 
    minSdkVersion 16 
    targetSdkVersion 21 
    versionCode 4 
    versionName "1.3" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
sourceSets { 

    main { 
     res.srcDirs = [ 
       "/src/main/res" 
     ] 
    } 
} 
dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile files('libs/thermodosdk-1.0.18.jar') 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile 'com.google.android.gms:play-services:6.5.87' 
compile 'com.android.support:support-v4:21.0.3' 

build.gradle在頂層有以下類路徑:

dependencies { 
    classpath 'com.android.tools.build:gradle:1.0.0' 
} 

堆棧跟蹤:

Information:Gradle tasks [:app:generateDebugSources,  :app:generateDebugTestSources] 
:app:preBuild 
:app:preDebugBuild 
:app:checkDebugManifest 
:app:preReleaseBuild 
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE 
:app:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE 
:app:prepareDebugDependencies 
:app:compileDebugAidl UP-TO-DATE 
:app:compileDebugRenderscript UP-TO-DATE 
:app:generateDebugBuildConfig UP-TO-DATE 
:app:generateDebugAssets UP-TO-DATE 
:app:mergeDebugAssets UP-TO-DATE 
:app:generateDebugResValues UP-TO-DATE 
:app:generateDebugResources UP-TO-DATE 
:app:mergeDebugResources UP-TO-DATE 
:app:processDebugManifest UP-TO-DATE 
:app:processDebugResources 
/Users/vidhigoel/AndroidStudioProjects/OMGAndroid/app/build/intermediates/manifests/full/debug/AndroidManifest.xml 
Error:(24, 23) No resource found that matches the given name (at 'icon' with value '@drawable/omg_app_icon'). 
Error:(25, 24) No resource found that matches the given name (at 'label' with value '@string/app_name'). 
Error:(27, 24) No resource found that matches the given name (at 'theme' with value '@style/AppTheme'). 
Error:(30, 28) No resource found that matches the given name (at 'label' with value '@string/app_name'). 
Error:(86, 28) No resource found that matches the given name (at 'label' with value '@string/app_name'). 
Error:(105, 28) No resource found that matches the given name (at 'label' with value '@string/app_name'). 
Error:(123, 28) No resource found that matches the given name (at 'label' with value '@string/app_name'). 
Error:(137, 28) No resource found that matches the given name (at 'label' with value '@string/title_activity_register_user'). 
... 
Information:BUILD FAILED 
Information:Total time: 4.462 secs 
Information:17 errors 
Information:0 warnings 
Information:See complete output in console 

請幫我解決這個問題。

+1

你可以張貼你的實際錯誤,如果可能的話,堆棧跟蹤。 – RaGe

+0

請發佈錯誤日誌以便於跟蹤 –

回答

1

你並不真的需要這部分在build.gradle

sourceSets { 

    main { 
     res.srcDirs = [ 
       "/src/main/res" 
     ] 
    } 
} 
  1. 這是默認值,你不需要把它放在那裏。
  2. 你有錯誤的路徑。正如我所說這是默認路徑,並非真正需要,但如果你仍然想添加它check this post on SO看看如何正確添加它。

你也許只想說:

res.srcDirs = ['res'] 

取下build.gradlesourceSets部分。刪除上述配置後,做一個乾淨的和重建。爲了更安全一側也做一個File - > Invalidate Cache and Restart

+0

非常感謝。您的解決方案修復了錯誤 –

+0

很高興幫助... – AndroidMechanic

2

只是改變你的gradle類路徑。

更換

classpath 'com.android.tools.build:gradle:1.0.0' 

classpath 'com.android.tools.build:gradle:2.0.0-alpha3' 

編輯:

還需要添加舊版本的你AppCompact象下面這樣:

dependencies { 
... 
compile 'com.android.support:appcompat-v7:19.+' 
... 
} 
+1

com.android.tools.build:gradle'處於測試階段,並且'appcompat'版本非常舊。 –

0

試試這個鏈接,可以幫助您 Installing Gradle In OSX

也請檢查這一個點

你編譯SDK版本必須支持庫的主要版本匹配。

因爲如果您使用支持庫的版本23,則需要針對Android SDK的版本23進行編譯。

或者,您可以通過切換到最新的支持庫v22繼續編譯針對Android SDK的22版本。

+0

我正在使用支持庫的版本號 –

+0

然後用21版的sdk編譯 –

0

你嘗試「建設/清潔工程」?