【问题标题】:Is there an easier way to add gson to my project?有没有更简单的方法可以将 gson 添加到我的项目中?
【发布时间】:2015-06-15 11:07:35
【问题描述】:

如何使用 gradle 将 gson 添加到我的项目中?我只看到人们将文件添加到他们的项目中。我不想下载项目并把它放在我的。

【问题讨论】:

  • 一般来说,我们鼓励张贴者展示他们尝试过的东西,或者他们所做的研究。但是,我在这个问题上注意到这一点为时已晚 - 您似乎已经有了一个快速的答案!

标签: android


【解决方案1】:

compile 已过时,改用implementation

dependencies {

    implementation 'com.google.code.gson:gson:2.8.5'

}

附: 2019 年 8 月 7 日的版本

【讨论】:

    【解决方案2】:

    如果您使用的是 Android Studio,则可以使用以下工作流程,而不是手动更改 Gradle 文件:

    1. 文件 -> 项目结构 -> 模块 -> 应用程序 -> 依赖项选项卡
    2. 点击左下角的“+”,选择“库依赖”
    3. 在搜索字段中输入:“gson”并点击搜索
    4. 选择“com.google.code.gson:gson:2.8.5”

    【讨论】:

    • 感谢屏幕截图,让生活更轻松!
    【解决方案3】:

    在 app/build.gradle 中:

     dependencies {
        compile 'com.google.code.gson:gson:2.8.2'
    }
    

    【讨论】:

    • 诗歌!如此简单,却又太正确。 Muchas gracias Senior.
    • 截至 2017 年 3 月的最新版本为 2.8.0
    • 2.8.2 截至 2017 年 9 月 20 日。
    • 现在 implementation 'com.google.code.gson:gson:2.8.6' 因为 compile 已被弃用
    【解决方案4】:

    将关注添加到项目的build.gradle

    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile 'com.google.code.gson:gson:2.8.0'
    }
    

    Here 是更多信息的链接。

    【讨论】:

      猜你喜欢
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多