問題描述
所以我將 gson-2.2.4.jar 添加到 libs 目錄(我使用的是 android studio).我的項目找不到 Gson 的東西,所以我將它作為庫依賴項添加到項目結構"中的模塊中.當我嘗試運行該項目時,構建失敗并出現以下錯誤:
So I added gson-2.2.4.jar to the libs dir (I'm using android studio). My project couldn't find the Gson stuff so I added it as a library dependency to my module in the "Project Structure". When I try to run the project, the build is failing with the following errors:
Error:(12, 23) Gradle: package com.google.gson does not exist
Error:(37, 3) Gradle: cannot find symbol class Gson
Error:(37, 19) Gradle: cannot find symbol class Gson
為什么我不能讓它工作?我在別處讀到,如果將 Gradle 放在 lib 目錄中,Gradle 應該會自動處理所有內容.
Why can't I get this working? I read elsewhere that Gradle is supposed to handle everything automatically if it's put in the lib dir.
推薦答案
在項目結構設置中將其添加為依賴項是不夠的.該設置僅適用于 IDE.要真正構建,Gradle 還需要意識到這一點.您必須像這樣將 .jar 文件添加到 build.gradle 文件中......
Adding it as a dependency in the Project Structure settings is not enough. That setting is only for the IDE. To actually build, Gradle also needs to be aware of it. You must add the .jar file to your build.gradle file like so...
dependencies {
compile files('libs/gson-2.2.4.jar')
}
這篇關于Android Gradle 找不到符號類 Gson的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!