question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RN0.66][Android] Direct local .aar file dependencies are not supported when building an AAR.

See original GitHub issue

Description

I have 3 rn modules that uses aar files. They reference it in their own build.gradle file like this:

compile files('libs/mylib.aar')

Until now, it was working fine.

I recently upgraded my app project from react native 0.63 to react native 0.66 and now when I assembleRelease it, I get:

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).

I workaround the problem by importing those aar files in my app’s build.gradle file but that sucks, my app should not be aware of those aar files at all…

Is there any way to use aar files in rn modules now with gradle 4.2+ ?

Version

0.66.3

Output of npx react-native info

$ npx react-native info info Fetching system and libraries information… System: OS: macOS 12.1 CPU: (10) arm64 Apple M1 Max Memory: 11.16 GB / 64.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0 Android SDK: API Levels: 18, 23, 24, 25, 26, 27, 28, 29, 30, 31 Build Tools: 23.0.1, 23.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.2, 28.0.3, 29.0.0, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0 System Images: android-19 | Google APIs Intel x86 Atom, android-21 | Google APIs Intel x86 Atom, android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-25 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom Android NDK: 20.1.5948944 IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: 13.1/13A1030d - /usr/bin/xcodebuild Languages: Java: 11.0.8 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.3 => 0.66.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

1 - Create or reuse a react native module that references a .aar file, 2- Try to gradlew assembleRelease the react native app project. You will run into this error.

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
marcshillingcommented, Aug 30, 2022

@a-eid here’s how I got past this:

  1. Patch the problematic 3rd party dependency’s build.gradle file. Under their dependencies { } section, they had a line like this:
    implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) //Load all aars and jars from libs folder
    
    My patch changes that line to:
    implementation(name: 'the-name-of-the-aar', ext: 'aar')
    
  2. In my project’s build.gradle, under allprojects { repositories { }, added:
    flatDir { dirs "$rootDir/../node_modules/the-third-party-dependency/android/libs" } 
    
    Where the AAR file lives
3reactions
zabojadcommented, Aug 25, 2022

Hi @marcshilling and @a-eid ,

So here is what you can do:

  • in your main RN application, put you aar files in android/app/libs,

  • then edit your android/app/build.graddle file and add this line:

    // … dependencies { // … implementation fileTree(dir: “libs”, include: [“*.aar”]) // ADD THIS LINE // …

  • in your react native module(s), everywhere your had this:

    implementation fileTree(include: [‘*.jar’], dir: ‘libs’)

or this

compile files('libs/mylib.aar')

replace it by this:

compileOnly files('libs/mylib.aar')

re-add your rn modules, recompile the rn project and it will work. But the sad thing here is that your react native project has now direct refs to your rn modules aar files which sucks big time.

If you guys find a better way to do that without publishing the aar files to a distant repo like Maven as suggested by @cortinico , I’d be very interested in your inputs on how you manage to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Direct local .aar file dependencies are not supported
I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New ->...
Read more >
Direct local .aar file dependencies are not supported - YouTube
Android : Error building Android library: Direct local . aar file dependencies are not supported [ Beautify Your Computer ...
Read more >
Not being able to import JAR/AAR package in new Intellj ...
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android...
Read more >
React native [0.66.4][android] - direct local .aar file ...
React native [0.66.4][android] - direct local .aar file dependencies are not supported when building an AAR.
Read more >
完美解决Direct local .aar file dependencies are not ...
最近gradle升级了,然后编译就出现了这个错误Direct local .aar file dependencies are not supported when building an AAR.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found