如何通过编辑build.gradle在Android的工作室把我的的android.jar面前库我的、面前、编辑、工作室

2023-09-12 22:58:20 作者:降龙十巴掌

首先这里是在Eclipse中我的Java构建路径:

这四个罐子'common.jar,core.jar添加,framework.jar,layout.jar'是从Android源$ C ​​$ C,其中包含一些类,不能公开使用developer.They needn'打包吨要出口,因为它们是为作弊编译器。在Eclipse中一切正常。

现在我想我的项目导入到Android的工作室gradle.I've添加的jar依赖关系,但我不能改变我的罐子和瓶子的android编译顺序。我不能把这些罐子在安卓jar.I'm不熟悉的摇篮前,现在的编译器找不到类在这些罐子。任何帮助将AP preciated! 这是我的build.gradle:

 应用插件:'机器人'
依赖{

    编译文件(罐子/ common.jar)
    编译文件(罐子/ core.jar添加)
    编译文件(罐子/ framework.jar)
    编译文件(罐子/ layout.jar)
    编译文件树(导演:库,包括:的* .jar)
    编译文件(罐子/ animation_nineoldandroids_src.jar)
    编译文件(罐子/ json_simple_src.jar)
    编译文件(罐子/ jsoup-1.7.2-sources.jar)
}

安卓{

    compileSdkVersion 17
    buildToolsVersion21.1.1
    sourceSets {
        主要 {
            manifest.srcFile的Andr​​oidManifest.xml
            java.srcDirs = ['src'中]
            resources.srcDirs = ['src'中]
            aidl.srcDirs = ['src'中]
            renderscript.srcDirs = ['src'中]
            res.srcDirs = ['水库']
            assets.srcDirs = ['资产']
        }

        //移动测试,测试/ java中,测试/ RES等...
        instrumentTest.setRoot(测试)

        //将建设各类建设类型/<类型>
        //例如,构建类型/调试/ java中,构建类型/调试/ AndroidManifest.xml中,...
        //这会将他们从src下他们默认位置/<类型> / ...这将
        //与SRC /冲突正在使用的主要来源集中。
        //添加新的构建类型或产品的口味应附有
        //通过类似定制。
        debug.setRoot(集结类型/调试)
        release.setRoot(集结类型/释放)
    }
}
 

解决方案 android studio 主工程build gradle是哪个

您不能做你想做的摇篮(*)是什么,至少在可预见的未来的时候这样写。有几个问题让你的方式:

在摇篮没有做相关性排序在构建类路径的方式Eclipse一样,这是你在做什么把你的类提前的android.jar 的。有摇篮​​的理念,你应该更加明确一些依赖于构建这样发生了什么事情是可以理解的,可重复的;依赖于类路径订货系统往往是微妙而脆弱的。所以,你会是什么需要做的是告诉摇篮,你的项目依赖于您的自定义类,而不是的android.jar ,但该插件的DSL不给你的手段去做。有在 http://forums.gradle.org/gradle/topics/classpath_ordering_again 一些讨论和 http://www.gradle.org/docs/current/userguide/dependency_management。 HTML 在看它的另一种方式是参照的android.jar 很难coded进入Android的摇篮插件,所以你不能在那个依赖并用别的东西代替它。

(*)说了这么多,没有什么是不可能的 - 你可以把它的工作,但你将不得不砍的东西在一起,所以这将是更多的麻烦多发比Eclipse的做法,强硬在SDK和工具的更新面部保持。而且出问题的时候,你会是你自己的。

您可以组装与自己的的android.jar 自己的自定义SDK。 您可以砍了Android摇篮插件。这种做法肯定是艰难的 - 学习曲线有pretty的陡峭和code是下重发展,这将是一个维护的负担,当你试图熬夜到最新的

我毫不犹豫地提供更多的洞察无论这些方法,一方面是因为我不知道很多关于它,可以pretty的轻松给你不好的建议,部分原因是因为我不想让没有经验的开发商看到这认为这是一个真棒的事情。但是,如果你看着办吧,这将是非常值得撰写的,因为我以前见过这样的问题,所以你不是唯一的一个。

First Here's my Java Build Path in Eclipse:

These four jars 'common.jar,core.jar, framework.jar,layout.jar' are packaged from Android source code, which contains some classes that can't be publicly used by developer.They needn't to be exported because they are for cheat compiler. In Eclipse everything is OK.

Now I'm trying to import my project to Android-Studio with gradle.I've add the jars to dependencies,However I can't change the compile order of my jars and android jar. I can't put these jars in front of android jar.I'm not familiar with gradle, now the compiler can't find classes in these jars. Any help will be appreciated! Here's my build.gradle:

apply plugin: 'android'    
dependencies {

    compile files('jars/common.jar')
    compile files('jars/core.jar')
    compile files('jars/framework.jar')
    compile files('jars/layout.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile files('jars/animation_nineoldandroids_src.jar')
    compile files('jars/json_simple_src.jar')
    compile files('jars/jsoup-1.7.2-sources.jar')
}

android {

    compileSdkVersion 17
    buildToolsVersion "21.1.1"
    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')
    }
}

解决方案

You can't do what you want in Gradle(*), at least for the foreseeable future at the time this is written. A few problems are getting in your way:

Gradle doesn't do ordering of dependencies in the build classpath the way that Eclipse does, which is what you were doing to put your classes ahead of android.jar. Gradle has the philosophy that you should be explicit about dependencies in your build so what's going on is understandable and repeatable; systems that rely on classpath ordering tend to be subtle and fragile. So what you would need to do is to tell Gradle that your project depends on your custom classes and not android.jar, but the plugin's DSL doesn't give you the means to do that. There's some discussion at http://forums.gradle.org/gradle/topics/classpath_ordering_again and http://www.gradle.org/docs/current/userguide/dependency_management.html Another way of looking at it is a reference to android.jar is hardcoded into the Android Gradle plugin, so you can't get at that dependency and replace it with something else.

(*) Having said all that, nothing is impossible -- you could make it work, but you're going to have to hack something together, so it's going to be more trouble-prone than the Eclipse approach, and tougher to maintain in the face of SDK and tooling updates. And when something goes wrong you'll be on your own.

You could assemble your own custom SDK with your own android.jar. You could hack the Android Gradle plugin. This approach would definitely be tough -- the learning curve there is pretty steep, and the code is under heavy development, which would be a maintenance burden as you try to stay up-to-date.

I hesitate to offer much more insight into either of those approaches, partly because I don't know a lot about it and could pretty easily give you bad advice, and partly because I don't want inexperienced developers seeing this to think it's an awesome thing to do. But if you figure it out, it would be very much worthy of writing up, because I've seen this sort of question before, so you're not the only one.