I am building a react native android library which depends on:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.5'
}
It turned out that android-maps-utils isn't working the way I want so I forked it and I wanted to use my version of this library instead of the official one. I can't find a way to do it though, I searched how to import a library from github inside gradle and I found ajoberstar/gradle-git but there is no clear instruction on how to do it and all examples I found doesn't work for me (for example this one: Gradle: how to clone a git repo in a task?). Is there any easier way on how to accomplish something like that?
EDIT:
This is my structure (simplified):
root:
| build.gradle
| settings.gradle
| aars
| map-util.aar
| libs
| android
| build.gradle
root build.gradle -> repositories { flatDir { dirs 'aars' } }
settings.gradle ->
include ":react-native-maps-lib"
project(":react-native-maps-lib").projectDir = file("./lib/android")
android/build.grandle -> compile(name: "map-util", ext:"aar")
Reference the AAR you build from building the forked source somewhere on your local filesystem.
repositories {
flatDir {
dirs 'libs'
}
}
then put the artifact in .../libs, and add it normally to your dependencies, of course matching the version to what you just built.
I figured out what is the problem! Let me first make clear though what I wanted to do - I'm building react native project. It uses my forked version of react-native-maps, which uses android-maps-utils. I wanted to fork android-maps-utils and use my forked version.
android-maps-utils produces aar file that I needed to import locally. Following Jeffrey Blattman suggestion I added libs directory inside react-native-maps and put aar file named android-maps-utils.aar there.
I also added this inside react-native-maps build.gradle:
allprojects {
repositories {
...
flatDir {
dirs "$rootDir/libs"
}
}
}
and this inside react-native-maps/android/build.gradle:
dependencies {
...
compile(name: "android-maps-utils", ext:"aar")
}
Now react-native-maps compiles but my react-native project doesn't due to:
A problem occurred evaluating project ':react-native-maps'.
So, I also needed to include this line:
compile(name: "android-maps-utils", ext:"aar")
inside my react native app android directory. Now everything compiles!
Related
I am trying to add a Flutter Module to a native Android app via an .aar file.
I followed the steps here:
https://flutter.dev/docs/development/add-to-app/android/project-setup
I create a new Android project. I also created a new Flutter Module independently (different location and IDE project outside of the Android project). Then I built an .aar via flutter build aar of the module. Then I created a module from that .aar file in the Android project.
Unfortunately, I can not get it to work. After adding the aar module, I can not access FlutterActivity, FlutterEngine etc. Only FlutterFragment and Flutter under io.flutter.facade are available. I can not see the io.flutter.embedding package.
Apparently, the Flutter dependencies are not included in the .aar archive. I tried various "fat aar" build scripts. No success. Also, as I understand, the described approach with the flutter build aar should contain all necessary Flutter dependencies, right?
Some people seem to got it to work. Unfortunately, there is no example project or specific help about the .aar approach anywhere.
Can someone help?
Add this in your AndroidManifest.xml
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="#style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"/>
Refer this below link
https://flutter.dev/docs/development/add-to-app/android/add-flutter-screen?tab=custom-activity-launch-kotlin-tab
This might help you.
You're right, AAR should contain all dependencies so from the native side, you don't need to do any extra steps, maybe you missing include one of them
maven {
url "$project.rootDir/../duy_flutter_module/build/host/outputs/repo"
}
maven {
url 'http://download.flutter.io'
}
remember that if your android native project has 2 modules, app and second module (contain an activity host your Flutter), your need to add AAR to both modules or add to build.gradle root inside allprojects block.
You can refer to here https://github.com/duytq94/demo-integrate-flutter
I was able to add Flutter module to Android via stand alone .aar.
Steps to add Flutter build aar to Android Native
Add aar to app/libs folder.If dont have libs folder create one.
Under app build.gradle
add
repositories
{
flatDir
{
dirs 'libs'
}
maven { url "https://storage.googleapis.com/download.flutter.io"}
maven { url 'https://maven.google.com' }
}
3.under dependencies in build.gradle.
Specify the aar that you are providing
dependencies {
implementation(name: 'flutter_release-1.0', ext: 'aar')
implementation 'io.flutter:flutter_embedding_release:1.0.0-a9d'
implementation 'io.flutter:armeabi_v7a_release:1.0.0-a9d'
implementation 'io.flutter:arm64_v8a_release:1.0.0-a9d'
implementation 'io.flutter:x86_64_release:1.0.0-a9d'
}
These below implementation you can find under outputs -> repo -> com.packagae --- -> /flutter_release/1.0{version}/flutter_release{version}.pom file
implementation 'io.flutter:flutter_embedding_release:1.0.0-a9d'
implementation 'io.flutter:armeabi_v7a_release:1.0.0-a9d'
implementation 'io.flutter:arm64_v8a_release:1.0.0-a9d'
You can find pom as below image
I wanted to create react-native wrapper around android sdk of zoom.us (they provide video conference feature through that), I have created a git repo using their sdk https://github.com/manjeets12/ZoomApiWrapper, but problem is that they only provide .aar sdk and it is giving me error project with path ":sdkName" could not be found in project ':react-native-zoom-api-wrapper'
I tried to use many solutions liking putting .aar files within libs folder and compiling from there or using flatDir options, as they don't provide any maven repo alternative, I am not sure how should I proceed in using this
So I've found a solution:
My aar-name is: 'my_name.aar'. You need to add this file to the libs folder in the root of your android folder (same level as your build.gradle).
Your build.gradle file has to contain this:
dependencies {
compile(name:'my_name', ext:'aar')
}
repositories {
flatDir {
dirs 'libs'
}
}
Your android project should compile then. Next step is to integrate the library to react-native.
npm install --save your_project
react-native link your_project
And finally add this to your android/app/build.gradle
repositories {
flatDir {
dirs "../../node_modules/your_project/android/libs"
}
}
For a working project see this git: https://github.com/transistorsoft/react-native-background-geolocation/blob/master/docs/INSTALL-ANDROID-RNPM.md
I have an Android application made up of multiple projects. One of those projects is an App project that just extends the Application object.
Inside the build.gradle for that app project, I add other projects as dependencies.
I've just created a new module to house an SDK (aar) I want to use. I've also added it to my app project's build.gradle.
compile project(':newmodule-thesdk')
Inside the libs folder of newmodule-thesdk, I have added the aar file. We'll call it thesdk.aar.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'thesdk-1.0', ext:'aar')
}
When I attempt to sync gradle, the sync fails because thesdk-1.0 does not exist in the libs folder of my app project. Why is it looking for it there? Why is it not just finding it in the newmodule-thesdk project?
It appears solving the problem required me to do the following in my App project's build.gradle.
repositories {
flatDir {
dirs project(':newmodule-thesdk').file('libs')
}
}
I had the similar problem and I just changed my xxx.aar to xxx-N.N.aar, in your case thesdk.aar to thesdk-1.0.aar and then it worked fine
You just have to change your code this way
dependencies {
compile fileTree(include: ['thesdk-1.0.aar'], dir: 'libs')
}
Keep in mind that the file should exist!
u could do 2 approaches
1) As you already said it:
repositories {
flatDir {
dirs project(':newmodule-thesdk').file('libs')
}
}
it can be done in this way
2)you can make a new gradle project with including the sdk and reference the old code project in it.
and then reference old project when u dont want to include the sdk and when you want to include the sdk reference the new gradle project
Whenever I add a android library-project as module to my Android Studio project, the sources get copied to the Android Studio project folder.
Is there a way to solve it like in eclipse, where there is only one copy of library project, any many projects can reference it?
You have different ways to achieve it:
using a local module referring the right path
adding an aar file
using a maven repo
CASE 1:
Using gradle and a local library, inside a project you can refer an external module.
Just use:
Project
|__build.gradle
|__settings.gradle
|__app (application module)
|__build.gradle
In settings.gradle:
include ':app'
include ':myLib'
project(':myLib').projectDir=new File('pathLibrary')
In app/build.gradle:
dependencies {
compile project(':myLib')
}
Pay attention to myLib.
You have to use the path of the library inside the other project, not the root of the project.
CASE 2:
Compile the library module, get the aar file, and then add to the main project:
Add the folder where you put the aar file as repository:
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
Then add the dependency:
dependencies {
compile(name:'nameOfAarFile', ext:'aar')
}
CASE 3:
Another way is to to publish your module into a maven repository.
In this way, just use:
dependencies {
compile ('mypackage:mymodule:X.Y.Z')
}
I would compile your shared code as library project. So you will get an aar file which you can reference.
To create that Android Archive you need to build the project as a release build with this command:
gradlew aR
After that you have a file called <modulename>-release.aar this file is located in <projectroot>/<modulename>/build/outputs/aar. I rename those files to <modulename>.aar then you can put it into your lib directory of your module.
When done you can reference it from the module where you need it like this:
compile(name:'<modulename>', ext:'aar')
This also speeds up the build time since you don't need to compile the project anymore.
I want to compile the following library in my project in build.gradle:
https://github.com/theDazzler/Android-Bootstrap
It is forked from https://github.com/Bearded-Hen/Android-Bootstrap, but no documentation in the repository explains how to include in in project.
I tried something like this:
compile 'com.theDazzler:androidbootstrap:+'
but gradle failed and shows error that library not found.
Edit: Can anyone fork it and/or publish it?
This fork isn't published in the maven central repo.
Then you can't use an import like compile com.theDazzler:androidbootstrap:+
You have to:
- clone this library locally as a module in your project
Clone the
https://github.com/theDazzler/Android-Bootstrap/tree/master/AndroidBootstrap folder in your root/module1 folder.
root:
module1
build.gradle
app
build.gradle
settings.gradle
Change your settings.gradle file in
include ':module1'
include ':app'
In your app/build.gradle file you have to add:
dependencies {
// Module Library
compile project(':module1')
}
Finally in your module1/build.gradle you have to check the level used for gradle plugin.
EDIT 31/10/2015:
You can use another way to add a dependency with a github project,using the github repo and the jitpack plugin
In this case you have to add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
It can be simply done by using Jitpack.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
for eg: compile 'com.github.sachinvarma:JcPlayer:0.0.1'
The issue is: has that theDazzler/Android-Bootstrap been published anywhere? In any gradle/maven repo?
The usual build.gradle file has a section repositories which should reference that maven repo.
So it is possible any project using theDazzler/Android-Bootstrap should reference the repo where it is published, And with a project like gradle-git-repo-plugin, you could publish that fork on its own release section to publish it.
That task gets wrapped into a publishToGithub task that handles committing and pushing the change. Then you can run
gradle -Porg=layerhq -Prepo=gradle-releases publishToGithub
You can also run
gradle -Porg=layerhq -Prepo=gradle-releases publish
to stage a release in the local github repo and commit it manually.
Hi i had the same issue but with a different project :)
So first you should have the library code on your dev machine.
Next steps are: add a new file called settings.gradle to the root of your project if its not already there.
inside add this:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "path/to/AndroidBootstrap/AndroidBootStrapLibrary"
also add include for your root project if its not there.
Inside your build.gradle file add
compile project(':AndroidBootStrap')
to add the dependency.
How your folder Structure should look:
root
YourProject
settings.gradle
YourProjectModule
build.gradle
AndroidBootStrap
AndroidBootStrapLibrary
build.gradle
In the end the files look like this:
settings.gradle:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "../AndroidBootstrap/AndroidBootStrapLibrary"
include 'YourProjectModule'
build.gradle (YourModule):
...
dependencies {
...
compile project(':AndroidBootStrap')
}
Maybe its necessary to modify some point but i hope you get the idea!
Cheers
Neri