Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Studio 3.2.0 sync error: Failed to transform android.jar #46

Open
jp1017 opened this issue Sep 25, 2018 · 39 comments
Open

Android Studio 3.2.0 sync error: Failed to transform android.jar #46

jp1017 opened this issue Sep 25, 2018 · 39 comments
Labels
IDE Error Android Studio as the IDE

Comments

@jp1017
Copy link

jp1017 commented Sep 25, 2018

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

@jp1017
Copy link
Author

jp1017 commented Sep 25, 2018

Sync success with api28

@zacharee
Copy link

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.

@KevinJe
Copy link

KevinJe commented Sep 26, 2018

The old version is ok! Gradle 3.2.0 is error in Sync.

@poloolop
Copy link

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

@zacharee
Copy link

You can keep using 4.6. Just change the classpath from 3.2.0 to 3.1.4.

@daio
Copy link

daio commented Oct 25, 2018

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

@anggrayudi anggrayudi added the IDE Error Android Studio as the IDE label Dec 5, 2018
@anggrayudi anggrayudi changed the title As 3.2.0 sync error Android Studio 3.2.0 sync error: Failed to transform android.jar Dec 5, 2018
@daio
Copy link

daio commented Dec 26, 2018

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.

@daio
Copy link

daio commented Dec 26, 2018

Of course it won't help with the issue of blacklisted APIs with the new Google policy.

@daio
Copy link

daio commented Dec 26, 2018

Here's android.jar for API level 28, which I use.

@jp1017
Copy link
Author

jp1017 commented Dec 28, 2018

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. 👍 😄

@NastuzziSamy
Copy link

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

@henrichg
Copy link

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.

@rgordeev
Copy link

rgordeev commented Feb 14, 2019

@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)

@henrichg
Copy link

henrichg commented Feb 14, 2019

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.

@chejdj
Copy link

chejdj commented Apr 19, 2019

I get the error too, but i replace the Api28 android.jar with origin Api28 android.jar, it is ok

@mleeaura
Copy link

mleeaura commented May 3, 2019

I wonder how @daio manages to make it work?.

@daio
Copy link

daio commented May 3, 2019

@mleeaura I've assembled it from AOSP sources. Seems like pulling framework from device no longer works.

@zacharee
Copy link

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

@adithyag
Copy link

adithyag commented Jun 3, 2019

@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?

@arncore
Copy link

arncore commented Jun 5, 2019

@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?

@daio
Copy link

daio commented Jun 5, 2019

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.

@adithyag
Copy link

adithyag commented Jun 5, 2019

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 ?

@daio
Copy link

daio commented Jun 6, 2019

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.

@arncore
Copy link

arncore commented Jun 6, 2019

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.

@daio
Copy link

daio commented Jul 24, 2019

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

@daio
Copy link

daio commented Jul 24, 2019

Oh yeah, it doesn't have internal resources because I don't need them

@belrvn
Copy link

belrvn commented Aug 29, 2019

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

@adithyag
Copy link

adithyag commented Sep 5, 2019

@daio can you share one with the latest AOSP release Q-R1? I think a few APIs have changed

@foezzy
Copy link

foezzy commented Sep 30, 2019

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

@juanjecilla
Copy link

@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.

@lgxace
Copy link

lgxace commented Mar 5, 2020

@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

@JetpackDuba
Copy link

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.

@JetpackDuba
Copy link

JetpackDuba commented Apr 27, 2020

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/

@henrichg
Copy link

henrichg commented Apr 28, 2020

@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.

@JetpackDuba
Copy link

You are welcome @henrichg . Let me know if you find any issues.

@SummerOak
Copy link

SummerOak commented May 13, 2020

DIsable lint check by adding the config works for me :

android {
    ....
    lintOptions {
        checkReleaseBuilds false
    }
   ...
}

@Reginer
Copy link

Reginer commented Nov 20, 2020

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

@gitaudotdev
Copy link

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

@feyisayo-dev
Copy link

could not resilve all files for configuration ':apps: AndriodapisFailed to transform android.jar to match attributes {artifactType=android-mockable-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, returnDefaultValues=false}.
Execution failed for MockableJarTransform: C:\Users\myname\AppData\Local\Android\Sdk\platforms\android-33\android.jar.
there is no andriod.jar in my folder only uiautomator.jar and I dont know what to do. very very new to android studio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE Error Android Studio as the IDE
Projects
None yet
Development

No branches or pull requests