[RN0.66][Android] Direct local .aar file dependencies are not supported when building an AAR.
See original GitHub issueDescription
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:
- Created 2 years ago
- Reactions:1
- Comments:11 (1 by maintainers)
@a-eid here’s how I got past this:
build.gradle
file. Under theirdependencies { }
section, they had a line like this: My patch changes that line to:build.gradle
, underallprojects { repositories { }
, added: Where the AAR file livesHi @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
replace it by this:
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.