android-hidden-api
android-hidden-api copied to clipboard
Android Studio 3.2.0 sync error: Failed to transform android.jar
As 3.2.0 sync error with api27 in this repo:
Could not resolve all files for configuration ':app:androidApis'. Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform
Sync success with api28
I have this issue too. It seems to be some sort of new verification in Gradle 3.2.0.
I changed my classpath back to 3.1.4 and it syncs fine. I wonder if there's a new Gradle setting to disable this or if we're out of luck.
The old version is ok! Gradle 3.2.0 is error in Sync.
Even I am facing a compilation issue with Android Plugin version 3.2.0 for latest Android Studio which forces Gradle version 4.6. It gives some translation issue with the SDK android.jar. Awaiting android.jar for API version 28
You can keep using 4.6. Just change the classpath from 3.2.0 to 3.1.4.
I think the change responsible for this issue is this one or something related to it: https://android.googlesource.com/platform/tools/base/+/acf0ab389c444a85371b897d8b2c81d96d31b988
Maybe it'll help figuring out how to workaround this
I have managed to sync with android gradle plugin 3.2.1, 3.3 RC and 3.4 alpha with android.jar assembled from .class files built from AOSP sources. When adding any .class from device's framework files to android.jar it fails to sync. You can check which classes fail with MockableJarGenerator from AOSP. It fails on line 134(classNode.accept method) on those classes that come from device's framework. You can add try/catch block and print all the class names that fail if you want. If you want to see how this class is used you can check this project.
Of course it won't help with the issue of blacklisted APIs with the new Google policy.
Here's android.jar for API level 28, which I use.
Here's android.jar for API level 28, which I use.
Thanks. You make it.
Gradle 4.10.3, gradle plugin: 3.2.1, compile successful, great job. :+1: :smile:
Hey guys, it does not work with Gradle >= 3.2 and SDK 27, still got the error :/
However, it is working with Gradle v3.1.4
NastuzziSamy this is OK. For compile SDK 27 is required gradle plugin 3.1.4. For compile SDK 28 is required gradle plugin 3.2.x.
@henrichg could you please explain what versions are compatible with each others. I've tried the following configuration for the project and it didn't work:
- Gradle wrapper
$ ./gradlew --version
---
Gradle 4.10.3
---
- Gradle Android build tool plugin
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
...
- SDK version
ext {
compileSdkVersion = 28
supportLibVersion = "28.0.0"
minSdkVersion = 26
targetSdkVersion = 28
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
}
....
dependencies {
// android libraries
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
And after
./gradlew build
I got
> Task :app:lint FAILED
Calling mockable JAR artifact transform to create file: /home/user/.gradle/caches/transforms-1/files-1.1/android.jar/7470a0577854d0dc407ece72235e8952/android.jar with input /home/rgordeev/Android/Sdk/platforms/android-28/android.jar
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Could not resolve all files for configuration ':app:androidApis'.
> Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform
> java.lang.IllegalArgumentException (no error message)
Use android.jar from @daio, attached in comment on 26 Dec 2018.
I'm using it with your confguration (except targetSDK = 27 and gradle 4.10.1) an working good. Builded in Android Studio 3.3.1.
I get the error too, but i replace the Api28 android.jar with origin Api28 android.jar, it is ok
I wonder how @daio manages to make it work?.
@mleeaura I've assembled it from AOSP sources. Seems like pulling framework from device no longer works.
Using the JAR from @daio works great for Pie. You can even bypass the hidden API restriction easily for your app, through Java or Kotlin.
Subclass the Application class, add it to your manifest, and put this in the onCreate()
method:
val forName = Class::class.java.getDeclaredMethod("forName", String::class.java)
val getDeclaredMethod = Class::class.java.getDeclaredMethod("getDeclaredMethod", String::class.java, arrayOf<Class<*>>()::class.java)
val vmRuntimeClass = forName.invoke(null, "dalvik.system.VMRuntime") as Class<*>
val getRuntime = getDeclaredMethod.invoke(vmRuntimeClass, "getRuntime", null) as Method
val setHiddenApiExemptions = getDeclaredMethod.invoke(vmRuntimeClass, "setHiddenApiExemptions", arrayOf(arrayOf<String>()::class.java)) as Method
val vmRuntime = getRuntime.invoke(null)
setHiddenApiExemptions.invoke(vmRuntime, arrayOf("L"))
https://stackoverflow.com/questions/55970137/bypass-androids-hidden-api-restrictions/55970138
@mleeaura I've assembled it from AOSP sources. Seems like pulling framework from device no longer works.
@daio can you please share how to build the android.jar with hidden APIs from AOSP sources or link to a guide?
@mleeaura I've assembled it from AOSP sources. Seems like pulling framework from device no longer works.
I did the same, however mine is also not working. I wonder how you are merging framework.jar and existing android.jar. I just unzip them both on a folder and rezip them. What process are you following if you don't mind sharing?
Sorry, kind of busy lately and I don't have the environment to repeat the process right now. When Android Q is released I'll probably do it again. Basically I just merged some intermediate jars with command-line utility 'jar'. I don't remember doing anything special, but I may be forgetting something.
Sorry, kind of busy lately and I don't have the environment to repeat the process right now. When Android Q is released I'll probably do it again. Basically I just merged some intermediate jars with command-line utility 'jar'. I don't remember doing anything special, but I may be forgetting something.
Was it something described here https://stackoverflow.com/a/9118795 ?
Something like that. As I remember, I also used MockableJarGenerator from the post above to determine which classes fail the transform. I could have removed some of those.
Something like that. As I remember, I also used MockableJarGenerator from the post above to determine which classes fail the transform. I could have removed some of those.
Haha. Yeah that's where the money is. I haven't played with it but yours worked for me so I've been using it and it works great.
I tried to reproduce the same steps I did last time with P for Q preview 5, but failed. So I had to improvise and generated android.jar from original android.jar + framework.jar made with turbine(it's a tool that makes a headers-only jar during AOSP build). The downside is that now if you try to browse the sources using Android Studio decompiler, then you're out of luck now as all of the methods have the bodies stripped after turbine. Anyway, here's android.jar with hidden APIs available for compilation of your apps. android.zip
Oh yeah, it doesn't have internal resources because I don't need them
Receiving this kind of error from CI pipe.
Calling mockable JAR artifact transform to create file: /home/travis/.gradle/caches/transforms-2/files-2.1/f22ba2b798712eea152cb64aedf1f5a9/android.jar with input /usr/local/android-sdk/platforms/android-28/android.jar
@daio can you share one with the latest AOSP release Q-R1? I think a few APIs have changed
Here's android.jar for API level 28, which I use.
把api28下载下来的jar包替换成这个,这个后缀zip要改成jar,然后同步就没报错了
download this .zip file then rename suffix to .jar replace the api28 jar downloaded in this project, it works
gradle/5.1.1 gradle tool:3.4.0 api28
@daio jar works fine for compilation but when I try to run unit tests, it fails. Does anyone try to fix that? I am using Android 28.
@daio I want to compile all the APIs (@hidden,@systemAPi,@unsupportAppUse,etc) to android.jar for androidx(android Q), could you please share the means or steps?
Thanks a lot, Ace
I've also been able to generate an android.jar with AOSP hidden API that works with newer Gradle versions (tested with 6.2). This week (probably tomorrow) I'll share the steps and even a script.
Checkout this repo I've just created. It contains a modified android.jar with android 10 & also the steps the generate your own. https://github.com/aeab13/android-jar-with-hidden-api/
@aeab13 Tested android.jar form https://github.com/aeab13/android-jar-with-hidden-api/ and working good for my application PhoneProfilesPlus. Thank you very much.
You are welcome @henrichg . Let me know if you find any issues.
DIsable lint check by adding the config works for me :
android {
....
lintOptions {
checkReleaseBuilds false
}
...
}
I fix it .
com.android.tools.build:gradle:4.1.0
, same as other versions.
Create class com.android.builder.testing.MockableJarGenerator
by IDEA
method:
public void createMockableJar(File input, File output) throws IOException {
}
build project.
Replace class com.android.builder.testing.MockableJarGenerator
in builder-4.1.0.jar
located in gradle path\caches\modules-2\files-2.1\com.android.tools.build\builder\4.1.0\aec0494498d0c8b9b46c226bf0ff02d73a299cac
details in https://blog.csdn.net/qq_26413249/article/details/109819624
Solved this issue by locating the Platforms folder on local machine @ C:\Users\user\Appdata\local\Android\sdk\platforms deleted the platform version that had issues in my case android-30 then reopened my IDE and proceeded to redownload the SDK again. The error dissappeared