Use customized framework library(android.jar) within Android Studio - android

I had my own customized framework(android.jar) and want to use it within Android Studio. I had description in my build.gradle like:
dependencies {
compile files('myandroid.jar')
}
But Android Studio still use the default framework(android.jar). Expected situation is like Eclipse, I can arrange the order of libraries. In Android Studio, I can only arrange external libraries' order and have nothing to do with the default framework library. Is there a way to let my customized android.jar had higher order than the default one?
Thanks a lot!

Place this line inside your dependencies:
provided files('libs/myandroid.jar')
If still not work, so we can add our library to build classpath. In application's build.gradle, add these:
allprojects {
repositories {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\mylibs.jar')
}
}
}
I placed mylib.jar is in app/libs. There maybe some errors display on IDE, but application's build will be OK.

What you can do is adding your .jar in your libs folder, then right clic on it and select add as a library.
Then if it doesnt work already, try to right clic on your project folder and select Open Modules settings. You can manage your dependency and your libraries there.

Try this ,In your modules's build.gradle file .
dependencies {
compile files('libs/myandroid.jar')
}

Try this:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:/mylib.jar')
}
}
}
http://www.jianshu.com/p/a25a85b6372d
How to put my libraries in front of android.jar by editing build.gradle in Android-Studio

Related

Replacing a gradle dependency in Flutter library

I'm writing a Flutter app that uses the "flutter_reactive_ble" plugin. That plugin, in turn, uses "RxAndroidBle" java library. I have made a small change to RxAndroidBle, and it compiles into .aar files. But my Gradle-fu is insufficient to figure out how to tell flutter_reactive_ble to use my version instead of retrieving the latest version from the web. I'd be happiest if I could just point to my local .aar files, but if I have to serve them from my own site, that would be OK as well.
After building my app, the "android/app/build.gradle" file ends with:
dependencies {
. . .
implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1"
}
I assume that's what I'll need to change, but nothing I can find in the Gradle docs look like what I need.
I think, you need fork repo first
And .yaml set like this
(read this)
I think you can do something like this in gradle:
configurations.each {
c -> c.resolutionStrategy.dependencySubstitution {
all { DependencySubstitution dependency ->
if (dependency.requested.group == 'com.polidea') {
dependency.useTarget '<your grade plugin>'
}
}
}
}
It can be replaced alike this:
configurations.all {
exclude group: 'com.polidea.rxandroidble2', module: 'rxandroidble'
}
dependencies {
implementation files('libs/rxandroidble.aar')
// or depend on the module.
}
If you want your app to use your aar, then just declare it as dependency. Or you want the flutter_reactive_ble to use it? I don't think it's possible. You'd have to make pr to RxAndroidBle and then pr to flutter_reactive_ble to take that version in.
I think overriding android dependency may solve your problem.
in build.gradle file of android project
configurations.all {
resolutionStrategy {
force ‘<android library with specific version>’
}
}
in your case:
force com.polidea.rxandroidble2:rxandroidble:1.11.1
check this link for more detail.
--------------------
for adding dependency of local project
in your settings.gradle file add mapping of your local project and include it
project(':local_project_name').projectDir = new File(settingsDir, '<relative path of project>')
include ':local_project_name'
And then add a resolutionStrategy in your project's build.gradle file
configurations.all {
resolutionStrategy {
force implementation project(':local_project_name')
}
}
You need to fork flutter_reactive_ble, go to build.gradle and remove this line then open android studio and open File > Project Structure > Dependencies:
Then Add your module library(.aar files you built):
in the end, android studio will add this line to build.gradle:
implementation(project(path: ":example-library"))
Make sure to use flutter_reactive_ble from your git repository inside your app, in your .yaml file add:
flutter_reactive_ble:
git:
url: your/git/flutter_reactive_ble/repository/url
ref: tag or commit id

importing an existing JAR or AAR as new project module

how to import JAR or AAR package as new project module in A new Android Studio Arctic Fox | 2020.3.1 Canary 9 ?
please let me know.
This works on Android Studio Arctic Fox Beta 02
Step 1 : Navigate to, File -> Project Structure. You can also press Ctrl+Alt+Shift+S
You will see a window just like below.
Step 2 : Click On app module as shown in image
Step 3 : Click on + icon as marked in image
Step 4 : You will see option to select jar/aar dependency. Click on it
You will see another window just like above asking you to specify path. Specify the path in which you kept the aar/jar file and hit Ok.
That should work
You can directly implement using JAR/ARR file path.
implementation files('/File Path/file.aar')
For Android Studio Bumblebee, original answer given here
I have followed steps suggested by the Android developer site:
Copy .aar file into the libs folder of the app
File -> Project Structure... -> Dependencies
Click on "+" icon and select JR/AAR Dependency and select app module
Add .aar file path in step 1.
Check your app’s build.gradle file to confirm a declaration.
Step 1: Put your aar file in the libs folder. And let’s take the file name is supernover.aar as an example.
Step 2: Put the following code in your Project level
build.gradle file,
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
and in the app level module write the below code,
dependencies {
Implementation(name:'supernover', ext:'aar')
}
Step 3: Then Click sync project with Gradle files.
If everything is working fine, then you will see library entry is made in build ->intermediates -> exploded-aar.
In my opinion, the best way to do this is to deploy the jar/aar to a local maven repository. if you install maven, you can use the mavenLocal() repository in gradle and read from there as with any other repo, regardless of the IDE you are using. All versions of Android Studio will work, all version of IntelliJ will work, VSCode will work, the command line will work, etc. Another advantage is, you'll be able to swap versions of the library as you do with all the others, just change the version in gradle (after deploying the new one), and will work for all your projects. Putting jars/aars manually into a project is just a bad practice, and reaaally outdated to top.
Once you installed maven, type this in your terminal:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Where you swap aar and jar depending on the type. The package name, group ID and library name are up to you, anything will work. I would use the library's package and name, and version 1.0 if you don`t have a version.
Here's an example link. Is old, but the process is the same. mvn install, then consume from mavenLocal().
For anyone in search of a solution still.
Create a new android Application project.
Convert new project into a standalone Library module.
Add maven-publish plugin to the module-level build.gradle
Connect your project to your Github repository (or create a new one).
In the module-level build.gradle, implement the Github Packages authentication flow. I'm using 'zuko' as an example - replace every instance of that name with your Github login.
android {
...
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/zuko/[git-repository]")
credentials {
username = 'zuko'
password = 'token' // this is a Git Personal Access Token
}
}
}
publications {
release(MavenPublication) {
groupId 'com.zuko.libraries'
artifactId 'choose-a-name'
version '1.0.0'
artifact("$buildDir/ogury-mediation-mopub-5.2.0.aar")
// you can actually put the artifact anywhere you want.
// This is the location of where you place your .aar file
}
}
}
...
}
If everything is connected properly, save your work, and run the the task: ./gradlew publish. The error logs are straightforward so just defer to the instructions and Google for more assistance.
To install a successfully published package into your desired project, use the same auth procedure for publishing.repositories, you don't need the second half, publishing.publications.
example: implementation 'com.zuko.libraries:choose-a-name:1.0.0'
You could configure a repository in you buildscript that looks for dependencies in a local directory
Use this to register a local directory as repository in your app module's build.gradle where libs is a directory under app module (<project>/app/libs/)
buildscript {
repositories {
flatDir { dirs 'libs' }
}
}
then declare your dependencies from the local file tree you registered earlier
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
This will include all jar/aar artifacts present under libs directory to be included in your module's dependencies.
PS: Local jar/aar artifacts will expect any transitive dependencies to be on the classpath unless they are fat-jars (package all transitive dependencies within the artifact), so these need to be added explicitly as dependencies.

Gradle looking for aar in wrong project's lib folder

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

No signature of method (or how to add a third-party library) in Android Studio

I have Android Studio 0.5.8. Here is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
dependencies {
compile files('libs/scala-compiler.jar', 'libs/scala-library.jar', 'libs/scala-reflect.jar')
}
}
I added the libs manually because right-mouse-click on the *.jar didn't cause to add the line compile files. But I'm getting the error now:
Error: No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection) values: [file collection]
Possible solutions: module(java.lang.Object)
How do I solve it?
Remove the dependencies block from the build file you posted in your question. Instead, add the library dependencies from the Project Structure dialog. In that dialog, choose the module you want to add dependencies for, select the Dependencies tab, click the + button, and choose "File dependency":
Having said that, if you've started your project in the last few months on anything approaching a recent version of Android Studio, it should automatically be picking up any libraries that are in the libs directory inside your module, via the line:
{dir=libs, include=[*.jar]}
If that line is present and it's not seeing the libraries, then perhaps you've put them in the wrong folder -- there's a libs directory inside your module where they should go. You may have to click the "Sync Project with Gradle Files" button in the toolbar to pick them up.

Use android-maps-utils in Android Studio

I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!

Categories

Resources