简体   繁体   English

在Android Gradle中订购库

[英]Ordering libraries in android gradle

I'm implementing a feature which requires accessing 'hidden' android API. 我正在实现一项功能,该功能需要访问“隐藏的” Android API。 I know that I could use Java-reflection but i have a compiled custom android jar with few selected classes which no longer contain 'hidden' field, which allows me to access certain parts of the 'private' android API. 我知道我可以使用Java反射,但是我有一个经过编译的自定义android jar,其中包含很少的选定类,这些不再包含“ hidden”字段,这使我可以访问“ private” android API的某些部分。

Due to the fact that i need to use 'gradle' to build my project (my teacher's requirement) i have stumbled upon a certain issue. 由于我需要使用“ gradle”来构建项目(我老师的要求),因此我偶然发现了一个问题。

Currently i have a jar: android-custom.jar -> which only contains "android.telephony.SmsMessage" 目前,我有一个jar:android-custom.jar->仅包含“ android.telephony.SmsMessage”

In Eclipse i can change the order of libraries from which the dependencies are taken, but in Gradle it seems that the first library for dependency discovery is taken from Android-sdk. 在Eclipse中,我可以更改从中获取依赖关系的库的顺序,但是在Gradle中,似乎第一个用于依赖关系发现的库是从Android-sdk获取的。

What i want to do is to use my android-custom.jar on-top of Android-sdk, while excluding both of them at runtime (either Android.jar nor my Android-custom.jar wouldn't be attached to my apk so my apk would use on device Android.jar). 我想要做的是在Android SDK的顶部使用我的android-custom.jar,同时在运行时将它们都排除在外(Android.jar和Android-custom.jar都不会附加到我的apk中,我的apk将在设备Android.jar上使用)。

Is this possible? 这可能吗?

This fixed my problem 这解决了我的问题

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {            
            options.compilerArgs << '-Xbootclasspath/p:/home/open-android.jar'
        }
    }
}

You may need to override the compileDebugJava/compileReleaseJava tasks with your own which includes custom library ordering. 您可能需要使用自己的覆盖自定义库排序的compileDebugJava / compileReleaseJava任务。 See here for a really old post on the same topic, sans Android. 请参阅此处 ,获得有关同一主题的非常古老的帖子,没有Android。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM