从迁移到Eclipse的Andr​​oid的工作室(gradle这个) [英] Migrating from Eclipse to Android-Studio (gradle)

查看:180
本文介绍了从迁移到Eclipse的Andr​​oid的工作室(gradle这个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的迁移应用程序使用gradle这个,但我面临着一些问题,包括库项目。

I'm trying to migrate my applications to use gradle, but I'm facing some problems including library projects.

我的项目树是这样的:

My projects root
- MyLib1
-- res
-- src
-- libs
- MyLib2
-- res
-- src
-- libs
- MyLib3
-- res
-- src
-- libs
- MyAppBase
-- res
-- src
-- libs
- MyApp - full version
-- res
-- src
-- libs
- MyAppFree - free version
-- res
-- src
-- libs

使用的Eclipse我有以下依赖性

With Eclipse I had the following dependencies

MyAppBase depends on:
-MyLib1
-MyLib2
-MyLib3

MyApp depends on:
-MyAppBase
-MyLib1
-MyLib2
-MyLib3

MyAppFree depends on:
-MyAppBase
-MyLib1
-MyLib2
-MyLib3

本组织在Eclipse中效果很好,但现在随着Android的Studio和gradle这个我有问题。

This organization worked well within Eclipse, but now with Android-Studio and gradle I'm having problems.

我有以下的build.gradle文件:

I've got the following build.gradle file:

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

dependencies {
    //compile project('../MyLib1')  <- error
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 4
        targetSdkVersion 14
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

如何能包括项目MyLib1,MyLib2,MyLib3作为依赖性,因此它会与我的项目?

How can I include the projects MyLib1, MyLib2, MyLib3 as a dependency so It will be compiled along with my project???

推荐答案

在present,所有依赖需要住项目的根目录下,所以你需要设置你的项目在目录植根上面的 MyLib1 MyLib2 的MyApp 等,这一限制将在未来被取消; // code:你可以在 HTTPS跟踪其进度.google.com / p /安卓/问题/细节?ID = 56367 。您的图书馆将是根目录下的库模块,和您的应用程序(S)将Android应用程序模块。每个模块都有自己单独的的build.gradle 文件,可以编译成JAR(普通的Java库),AAR(Android的图书​​馆,其中包括code +资源)或APK(Android应用程序)。

At present, all dependencies need to live under the project's root directory, so you'd need to set up your project to be rooted at the directory above MyLib1, MyLib2, MyApp, etc. This limitation will be lifted in the future; you can track its progress at https://code.google.com/p/android/issues/detail?id=56367. Your libraries would be library modules under that root, and your app(s) would be Android application modules. Each module has its own separate build.gradle file and can compile to a JAR (plain Java library), AAR (Android library, which includes code + resources), or APK (Android app).

我不知道,如果 MyAppFree 的MyApp 是分开的Eclipse项目;如果是这样,在Android的Studio和摇篮我鼓励你将它们组合成一个具有免费和付费的味道一个模块。构建口味的设计明确地帮助这种用例。见的http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors获取更多信息。

I'm not sure if MyAppFree and MyApp are separate Eclipse projects; if they are, under Android Studio and Gradle I'd encourage you to combine them into one module that has free and paid flavors. Build flavors are designed explicitly to aid this sort of use case. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors for more info.

更新

在下面的评论看起来你有一个非常大的数字图书馆。在你可能不希望从源代码构建所有所有的时间,或管理有几十个模块的一个项目。在这种情况下,保持不经常改变作为单独的项目模块更有意义。这些项目可以编译为JAR或AAR,这使我们回到你原来如何使Android Studio中的工作问题。

In the comments below it looks like you have a very large number of libraries. In that you probably don't want to build them all from source all the time, or manage a project that has dozens of modules. In that scenario, keeping modules that don't change very often as separate projects makes more sense. Those projects can compile to JAR or AAR, which brings us back to your original question of how to make those work in Android Studio.

您可以JAR文件复制到目录项目根目录下,并在链接它们,我相信有试图做同样的AAR库的问题。看到的https://$c$c.google.com/ p /安卓/问题/细节?ID = 63908 跟踪的进展。如果你不想保持库的多个副本,您既可以试试符号链接的目录(我的认为,将工作),或者你可以建立一个本地仓库,并有侧项目公布他们的神器了这一点。我没有上,在我的指尖详细说明的链接;你可以使用 http://www.gradle.org/docs/current/userguide启动/publishing_maven.html

You could copy JAR files into a libs directory under your project root and link them in. I believe there are problems trying to do the same with AAR libraries; see https://code.google.com/p/android/issues/detail?id=63908 to track the progress of that. If you don't want to maintain multiple copies of the libraries, you could either try symlinking the directories (I think that will work), or you could set up a local Maven repository and have the side projects publish their artifacts to that. I don't have links with detailed instructions on that at my fingertips; you could start with http://www.gradle.org/docs/current/userguide/publishing_maven.html.

将有一个公平的学习曲线获得一个本地Maven回购成立,但一旦做了,你可能会发现,它清晰地解决您的问题pretty,如果你是在具有多个商店开发商和想的全组织的Maven回购,也许这是从构建服务器发布到它的文物,你可以设置的。

There will be a fair learning curve to getting a local Maven repo set up, but once it's done, you'll probably find that it solves your problem pretty cleanly, and if you're in a shop with multiple developers and would like an organization-wide Maven repo, perhaps with artifacts that are published to it from a build server, you can set that up.

这篇关于从迁移到Eclipse的Andr​​oid的工作室(gradle这个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆