First Here's my Java Build Path in Eclipse:
common.jar,core.jar,framework.jar,layout.jar这四个jar是从Android源代码中打包出来的,其中包含一些开发者不能公开使用的类。它们不需要导出,因为它们用于作弊编译器。在 Eclipse 中一切正常。
现在我正在尝试使用 gradle 将我的项目导入到 Android-Studio。我已将 jar 添加到依赖项中,但是我无法更改 jar 和 android jar 的编译顺序。我不能把这些jar放在android jar前面。我对gradle不熟悉,现在编译器找不到这些jar中的类。任何帮助将不胜感激!
这是我的 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')
}
}
你不能在 Gradle(*) 中做你想做的事,至少在撰写本文时可预见的将来是这样。有一些问题阻碍了您:
- Gradle 不会像 Eclipse 那样对构建类路径中的依赖项进行排序,这就是您将类放在前面所做的事情
android.jar
。 Gradle 的理念是,您应该明确构建中的依赖关系,以便发生的事情是可以理解和可重复的;依赖类路径排序的系统往往是微妙且脆弱的。所以你需要做的是告诉 Gradle 你的项目依赖于你的自定义类而不是android.jar
,但是该插件的 DSL 并没有为您提供执行此操作的方法。有一些讨论在http://forums.gradle.org/gradle/topics/classpath_ordering_again http://forums.gradle.org/gradle/topics/classpath_ordering_again and http://www.gradle.org/docs/current/userguide/dependency_management.html http://www.gradle.org/docs/current/userguide/dependency_management.html
- 另一种看待它的方式是参考
android.jar
已硬编码到 Android Gradle 插件中,因此您无法获取该依赖项并将其替换为其他内容。
(*) 话虽如此,没有什么是不可能的——你可以让它工作,但是你必须将一些东西组合在一起,所以它会比 Eclipse 方法更容易出现问题,并且更难维护SDK 和工具更新的面貌。当出现问题时,你就得靠自己了。
- 您可以使用自己的自定义 SDK 来组装
android.jar
.
- 您可以破解 Android Gradle 插件。这种方法肯定会很困难——学习曲线相当陡峭,而且代码正在大量开发中,当您试图保持最新状态时,这将成为维护负担。
我犹豫是否要对这两种方法提供更多的见解,部分原因是我对此了解不多,很容易给您提供不好的建议,部分原因是我不希望经验不足的开发人员看到这一点并认为这是一个很棒的方法。要做的事。但如果你弄清楚了,那就非常值得写下来了,因为我以前见过这种问题,所以你不是唯一一个。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)