How to avoid use dependencies again (Android)? - android

I've created an Android library with Studio and this library needs some 3rd libraries. The build.gradle looks like below:
dependencies {
compile fileTree(dir: 'libs', include: ['*.*'])
compile 'some library:1.3.2'
compile 'some other library:1.3.4'
}
The library can be compiled freely and finely, and then I push them in to local Maven. Everything fine!
Now I create a client application just for a sample of my library. What confusion is that I must do follow:
dependencies {
compile fileTree(dir: 'libs', include: ['*.*'])
compile 'mylibrary:1.0'
compile 'some library:1.3.2'
compile 'some other library:1.3.4'
}
Which means to include the two 3rd libraries. Otherwise I must get errors "NoClassFound" which relevant to the two libraries.
You know the
compile 'mylibrary:1.0'
is the meaning to include my library, but why should I include the other twos which were used by "mylibrary"? Could I avoid that and just -compile 'mylibrary:1.0' ?

OK, I've solved project with the help of #CommonsWare
Check out
http://www.gradle.org/docs/current/userguide/publishing_maven.html
http://maven.apache.org/pom.html
To make a pom.xml self and done.

Related

Javapoet not found in processor

I created an Android library that uses JavaPoet to generate classes. It works well on my local workspace ; even if I include the library module into another project.
Now I'm trying to put my project online through bintray. The project is uploaded correctly, but then when I include it in a new project and build the projet I get this message :
Error:Bad service configuration file, or exception thrown while
constructing Processor object: javax.annotation.processing.Processor:
Provider me.aflak.filter_processor.FilterProcessor could not be
instantiated: java.lang.NoClassDefFoundError:
com/squareup/javapoet/TypeName
I guess it comes from the way I manage the dependencies... Compiletime, Runtime stuff...
This is processor build.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':filter-annotation')
api 'com.squareup:javapoet:1.9.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.google.auto.service:auto-service:1.0-rc3'
}
This is annotation buid.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.8.1'
}
This is how I include the library in an empty project :
// build.gradle project
repositories {
maven{
url 'https://dl.bintray.com/omaflak/maven'
}
}
// build.gradle module
dependencies {
compile 'me.aflak.libraries:filter-annotation:1.0'
annotationProcessor 'me.aflak.libraries:filter-processor:1.0'
}
Could someone point me out to the right direction ? Thanks !
I finally got the solution (a bit randomly though :p).
I had to add mavenLocal() in the library module.

How to add *.jack in android studio?

In android M, android support jack, and I compile the library and it is 3d.jack instead of 3d.jar.
My question is how to add 3d.jack as the library to build my app which depends on the library of 3d.
I know how to add a lib if the lib is 3d.jar. But I try to use same way, copy 3d.jack into libs folder, and change to *.jack, it doesn't work.
So anyone knows how to do it?
dependencies {
compile fileTree(dir: 'libs', include: ['*.jack'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
}
I have a workground method.
In the module where it make the .jack file, you can add
LOCAL_JACK_ENABLED := disabled
in the make file.Then it will generate .jar instead of .jack.
Then you can use the .jar as usual.

Android Studio - MavenCentral dependency sync ok, but symbol cannot be resolved

So, I managed to create an Android library component and publish it on Maven Central. But when I'm trying to use it as a dependency in a new project, Android Studio can't seem to find the classes.
build.gradle for the app module:
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'no.hyper:libdateintervalpicker:1.0.0' //this is the one I want to use
}
This part seems to work, at least I get no sync errors. However, when trying to access to package and classes from my MainActivity, Android Studio can't find them and gives me "cannot resolve symbol" message.
I have tried downloading the classes.jar from the archive directly from Maven Central, and they are indeed in the package.
Other dependencies seem to appear in the /build/intermediates/exploded-aar folder after syncing, but that does not happen to my library.
I use Android Studio 1.0.2 on OSX 10.9.5 (Mavericks)
Any suggestions?
Looking in your pom, it states <packaging>aar.asc</packaging>. It should be aar instead.
Oh, and the answer to actually being able to use the library, was to add #aar to the dependency so that it now reads
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'no.hyper:libdateintervalpicker:1.0.0#aar' //note the magic #aar
}
Edit:
Removing the block
configurations {
archives {
extendsFrom configurations.default
}
}
makes Gradle generate the pom with the correct packaging entry, and thus makes it possible to reference the dependency without the #aar suffix

Why my app is errors when I just create it?

I use android studio with sdk v24.
When I create my new application and just go to the MainActivity.jar It shows me many codes red?
Here it is that I'm talking about:(screen shot)
https://dl.dropboxusercontent.com/u/100174344/Screenshot%202015-01-06%2008.06.09.png
I'm really confused. How can I fix these errors?
NOTE: my sdk is up to date (as you see here: https://dl.dropboxusercontent.com/u/100174344/Screenshot%202015-01-06%2008.22.28.png )
and I've added this code to my build.gradle(Module: app) :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3' }
EDIT:
I'm sorry I create a new project and still it show me the codes, red but I can run it in AVD. what's the problem?
You want To add android.support.v7.jar not added that y i think this error occurs.
add this in your project property file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
}
Did you added android.support.v7.jar? Just make sure your sdk is updated and you've added android.support.v7.jar. Also check the dependencies.
You need to add appcompat v7 dependencies to the app gradle file.
Ensure build.gradle(Module : app) is having the dependency.
If not available then add and sync the project
It should be like-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
}
I found the problem
I don't know why but when I changed the theme by this structure the issue is up.

Android Studio with Gradle incompatibility (Google Play Services issue)

I am developing an android app with Android Studio 0.8.9. I am using Gradle to build my project.
I want to include google-play-services.jar file into my project in order to use push notification api.
I have added those statements into my gradle (application layer) file as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/google-play-services.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.2.3.jar')
compile files('libs/volley_23042014.jar')
compile 'com.google.android.gms:play-services:5.2.08'
}
but it never works. I get the following error:
Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
I've checked bunch of websites (including Stackoverflow.com). None of them has worked for me.
I have latest versions of Google Support Library, Google Support Repository, Google Play Services.
Here is my libs directory
My SDK version like:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="20" />
What I have done wrong? If anyone has any idea please let me know.
If you're including Play Services via:
compile 'com.google.android.gms:play-services:5.2.08'
you don't need this:
compile files('libs/google-play-services.jar')
so just remove it.
Since the first line of your dependencies will make it automatically pick up any jar files you put in your libs directory:
compile fileTree(dir: 'libs', include: ['*.jar'])
make sure you remove the jars from there as well.
For that matter, there are other libraries you shouldn't include via specific jars.
Instead of this:
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.2.3.jar')
use this:
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.code.gson:gson:2.2.3
(Note that later versions of GSON are available).

Categories

Resources