如何将番石榴添加到我的Android Studio项目中?

康拉德·莫拉斯基(Konrad Morawski)

首先,我知道这个问题的存在-如何将库项目添加到Android Studio?-不幸的是,它没有帮助我。

我的目标很简单。我想使用Android Studio IDE(0.2.11)和代码中Guava库编写一个Android应用程序

我不知道Gradle,我只是开始使用Android Studio,而我的Visual Studio / C#背景却使我失望了,对此我深表歉意(在那个米老鼠世界中,您通常只是添加一个库引用而已)。

我将用屏幕截图记录我的步骤。我大多遵循此答案中给出的建议

我在libraries项目文件夹下创建了一个文件夹。

在此处输入图片说明

我将Guava存储库克隆到其中。

在此处输入图片说明

文件成功出现。

在此处输入图片说明

我去Project Structure选了Import Module

在此处输入图片说明

在此处输入图片说明

我选择Create module from existing sources并同意所有默认选择。

我将settings.gradle文件更新include ':libraries:guava', ':Test'

在此处输入图片说明

和我的build.gradle文件compile project(":libraries:guava")

在此处输入图片说明

但是,每当我尝试重建项目时,我得到的就是:

Error: Gradle: A problem occurred configuring project ':Test'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.

我确实尝试build.gradleguava文件夹中放入如下内容

buildscript {
    repositories {
        mavenCentral()
    }

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

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

(如上述答案所述)。

我已经在谷歌上下搜索以找到build.gradle番石榴的“正确”字样

https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild - didn't help me, either.

I did try countless things which I will not describe here as they were rather haphazard - I tried adding a module dependency, I tried turning Use auto-import on in Gradle settings, etc.

I know it's not a way of solving issues and I promise I will diligently read Gradle's User Guide from 1 through 5.4.2 to 7.3, but I can't believe this is really prerequisite to achieve something as unremarkable as merely adding a library to a project? Why is there no default build.gradle file from which one could start to fiddle with all sorts of things if necessary?

And the real question - how do I create an app (in Android Studio) that builds, actually runs on an Android device and on the top of that allows me to use Guava so I could sort a map by values without writing 50 lines of code? :)

Sorry about the chatty tone of my question, I know the drill around here, it's just my way of venting my frustration off.

Judging by how many votes were casted for questions and answers that tackled similar issues, I'm sure I'm not the only one who would benefit from some more instructions. I would start a bounty on it straight away, but the rules forbid me.

jlhuertas

If you just need to use a stable, released version of the Guava libraries, importing it is extremely easy.

Just go to the build.gradlefile of the module where you want to use the library (i.e GuavaTestProject/GuavaTest/build.gradle) and, right after

repositories {
    mavenCentral()
}

add a Maven dependency:

dependencies {
    compile group: 'com.google.guava', name: 'guava', version: '15.0'
}

Rebuild your project if needed and that's all (tested right now with a fresh project created with Android Studio 0.2.13).

If you really need to include the source code of the Guava library and compile it yourself as a module of your Gradle build that's an entirely different problem because Guava is build with Maven and so you need to move the Guava build system from Maven to Gradle, which I think is overwhelmingly complex for your goals.

If you just need to browse the source or view it while debugging, what I would do is:

  • Download Guava source code on a separate folder:

    git clone https://code.google.com/p/guava-libraries/
    git checkout v15.0
    
  • When Android Studio doesn't find the sources, click on "Attach sources" and point to this alternative location.

我认为,如果您不需要实际修改和编译Guava源代码,这是最简单的解决方案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将此模块添加到我的Android Studio项目中?

来自分类Dev

如何将android支持库添加到我的netbeans项目中

来自分类Dev

如何将Bango SDK添加到我的android项目中?

来自分类Dev

如何将android支持库添加到我的netbeans项目中

来自分类Dev

我无法将支持库添加到我的Android Studio项目中

来自分类Dev

将第3方代码添加到我的Android Studio项目中

来自分类常见问题

如何将BundleConfig.cs添加到我的项目中?

来自分类Dev

如何将MP3添加到我的iOS / Xcode项目中?

来自分类Dev

如何将com.typesafe.sbt。*依赖项添加到我的项目中?

来自分类Dev

如何将dll文件永久添加到我的项目中?

来自分类Dev

试图弄清楚如何将GestureDetectorCompat添加到我的项目中

来自分类Dev

如何将Gulp添加到我的项目中?

来自分类Dev

如何将真实文件夹添加到我的Netbeans C项目中?

来自分类Dev

如何将dll文件永久添加到我的项目中?

来自分类Dev

试图弄清楚如何将GestureDetectorCompat添加到我的项目中

来自分类Dev

如何将远程子模块添加到我的github项目中?

来自分类Dev

如何将Gulp添加到我的项目中?

来自分类Dev

如何将 webrtc 原生 api 添加到我的 qt 项目中?

来自分类Dev

如何将 pod 添加到我的 flutter / iOS 项目中?

来自分类Dev

如何将监视模块添加到现有的Android Studio项目中?

来自分类Dev

如何将Google Play APK扩展库添加到android studio项目中?

来自分类Dev

如何将libgdx添加到现有的android studio项目中?

来自分类Dev

如何将`mock` 包正确添加到Android Studio 项目中?

来自分类Dev

如何将已编译的 C 代码添加到 android studio 项目中?

来自分类Dev

如何将CastCompanionLibrary作为依赖项添加到我的Android Studio模块?

来自分类Dev

使用Xamarin Studio将Lollipop工具栏添加到我的项目中

来自分类Dev

如何将 Nuget 包添加到我的 Visual Studio 扩展中的项目?

来自分类Dev

如何在Visual Studio中将jQuery DateTimePicker添加到我的项目中

来自分类Dev

无法将coreGraphics添加到我的项目中

Related 相关文章

  1. 1

    如何将此模块添加到我的Android Studio项目中?

  2. 2

    如何将android支持库添加到我的netbeans项目中

  3. 3

    如何将Bango SDK添加到我的android项目中?

  4. 4

    如何将android支持库添加到我的netbeans项目中

  5. 5

    我无法将支持库添加到我的Android Studio项目中

  6. 6

    将第3方代码添加到我的Android Studio项目中

  7. 7

    如何将BundleConfig.cs添加到我的项目中?

  8. 8

    如何将MP3添加到我的iOS / Xcode项目中?

  9. 9

    如何将com.typesafe.sbt。*依赖项添加到我的项目中?

  10. 10

    如何将dll文件永久添加到我的项目中?

  11. 11

    试图弄清楚如何将GestureDetectorCompat添加到我的项目中

  12. 12

    如何将Gulp添加到我的项目中?

  13. 13

    如何将真实文件夹添加到我的Netbeans C项目中?

  14. 14

    如何将dll文件永久添加到我的项目中?

  15. 15

    试图弄清楚如何将GestureDetectorCompat添加到我的项目中

  16. 16

    如何将远程子模块添加到我的github项目中?

  17. 17

    如何将Gulp添加到我的项目中?

  18. 18

    如何将 webrtc 原生 api 添加到我的 qt 项目中?

  19. 19

    如何将 pod 添加到我的 flutter / iOS 项目中?

  20. 20

    如何将监视模块添加到现有的Android Studio项目中?

  21. 21

    如何将Google Play APK扩展库添加到android studio项目中?

  22. 22

    如何将libgdx添加到现有的android studio项目中?

  23. 23

    如何将`mock` 包正确添加到Android Studio 项目中?

  24. 24

    如何将已编译的 C 代码添加到 android studio 项目中?

  25. 25

    如何将CastCompanionLibrary作为依赖项添加到我的Android Studio模块?

  26. 26

    使用Xamarin Studio将Lollipop工具栏添加到我的项目中

  27. 27

    如何将 Nuget 包添加到我的 Visual Studio 扩展中的项目?

  28. 28

    如何在Visual Studio中将jQuery DateTimePicker添加到我的项目中

  29. 29

    无法将coreGraphics添加到我的项目中

热门标签

归档