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')
}
}
The simplest solution for me was to replace
android.jar
with one with the hidden API included. Getandroid.jar
from this project library that provides access to Android hidden API and internal resources and place it to your ASDK platforms folder, to the platform you're compiling against (compileSdkVersion
).I'm sure it works with Eclipse as well ))
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:
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 notandroid.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.htmlandroid.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.
android.jar
.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.
Update app/app.iml file order as
Following script works for me:
You can do this automatically, just like in Eclipse:
File
>Project structure...
>(select app in Modules)
>(go to Dependencies tab)
>reposition with arrows on the right
Another way is to edit the [AppName].iml file in the folder your application is in. What you want to change are the tags at the end of the file. However, Android Studio will rearrange those each time you clean or re-open the project.
I solved the issue from this post to build application with system libraries :
Supposing you have added system libraries like
libframework.jar
andlibcore.jar
inapp/libs
:add
Xbootclasspath
to your top levelbuild.gradle
:in you app
build.gradle
, useprovided
:in the same app
build.gradle
, add a task to put<orderEntry>
referring toAndroid API 25 Platform
in the last position inapp.iml
, this way gradle will take into account your system libs first and Android SDK in last resort :