2013-06-02 59 views
16

我正在嘗試將我的項目中的.jar庫添加到/libs文件夾中。這裏是我的grade.buildAndroid Studio在Gradle編譯後無法找到庫類

buildscript { 
     repositories { 
      mavenCentral() 
     } 
     dependencies { 
      classpath 'com.android.tools.build:gradle:0.4' 
     } 
    } 
    apply plugin: 'android' 

    dependencies { 
     compile files('libs/android-support-v4.jar', 'libs/java-api-wrapper-1.2.0-all.jar') 
    } 

    android { 
     compileSdkVersion 17 
     buildToolsVersion "17.0.0" 

     defaultConfig { 
      minSdkVersion 15 
      targetSdkVersion 16 
     } 
    } 

之後我再補充一點,我建我的項目,並沒有錯誤。但是,當我嘗試使用這個類在我的代碼private ApiWrapper wrapper,我得到一個錯誤:

Gradle: error: cannot find symbol class ApiWrapper 

我不能完全找到錯誤所在。我的grade.build不好,或者我應該以其他方式構建它?

+0

你有任何的子項目,或只是一個主要項目的gradle?我在其中一個子項目中遇到了類似的錯誤... –

回答

22

使用命令行,在你的項目的根目錄,運行:
./gradlew clean && ./gradlew build

然後重新編譯你的項目工作室,你應該看到您的新庫。

+0

我想如果您運行Build - > Rebuild Project,它會爲Gradle運行assembleDebug任務,它會事先運行'clean'任務。 –

+0

非常感謝。該命令行解決方案有所幫助我很疲憊,爲我的問題尋找解決方案。但最後這工作 –

9
  • 作爲第一選擇,我認爲將足夠Syncronizing the Project with Gradle Files

enter image description here

  • 另一種選擇,在命令行中運行位於您的項目文件夾中的批處理文件gradlew.bat

enter image description here

./gradlew clean && ./gradlew build 
相關問題