Gradle Android library build but not resolve symbols - java

I am doing an android-library using Gradle and its build successfully, but when I open some class that uses this dependency not resolve sysmbols. Why?
In my build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
//myDependency
compile project(':myDependency')
}
Thanks.
Ps. My dependency is a pure Java project

Related

Gradle error after including facebook sdk

Immediately after adding the facebook-audience-network-sdk in my gradle file, I started getting errors, the first one I fixed my adding multiDexEnabled true, after that I keep getting this error
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqa.class
Here are my dependencies list in build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.mcxiaoke.volley:library:1.0.17'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
compile 'com.facebook.android:audience-network-sdk:4.10.0'
compile 'joda-time:joda-time:2.7'
}
After running gradle with -q dependencies here is my screenshot, I think the problem is related to google play services libraries seeing the facebook.android:audience-network-sdk depends on analytics 7.8.0 while I have included the latest 8.4.0 already in my dependencies, I'm not sure.
How can i fix this?
I finally got rid of the error. So the problem was with the com.google.android.gms:play-services-ads-8.1.0. You can see from the image it was 8.1.0 and other play dependencies were 8.4.0.
So these two ways worked. One was to change the dependency into
compile ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group:"com.google.android.gms"
}
But the issue with this is that, it could be a problem since in my other dependencies I didn't have play-services-ads:8.4.0'
So the way I solved this was just add a single line
compile 'com.google.android.gms:play-services-ads:8.4.0'
This way everything worked perfectly, because when gradle compiled it automatically replaced the 8.1.0 into the 8.4.0
Here is my final dependencies list that worked
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.mcxiaoke.volley:library:1.0.17'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
compile 'com.facebook.android:audience-network-sdk:4.10.0'
compile 'joda-time:joda-time:2.7'
}

android studio jar import problems

I am a freshman in android development and want to use webservice by some jars.(The webservice has been written and publish).
Then I use Ksoap.jar and Jsoup.jar.
In android studio. I try to import them. It shows successful but I still cannot use the classes in the jars.
The build.gradle shows below:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile files('libs/ksoap2-android-3.4.0.jar')
compile files('libs/jsoup-1.8.3-sources.jar')
}
But in my activity, I still cannot import them.
How can I solve this problem?
It drives me mad.
You don't need
compile files('libs/ksoap2-android-3.4.0.jar')
compile files('libs/jsoup-1.8.3-sources.jar')
As long as you have those jar files in the libs folder, this gradle line will include them in your project.
compile fileTree(dir: 'libs', include: ['*.jar'])
It says "for every jar file in the libs/ directory, compile it." Having those two additional lines is redundant.

How do I include another project's class libraries in my jar using Gradle?

I am developing for Android, and I am trying to include another project's class files in my .jar file.
My build.gradle file for library project looks like this:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.3'
compile project(':xyz')
}
My build.gradle file for xyz project looks like this:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
The issue is that when I create another project that includes my jar library, it has unresolved references that exist in my xyz project. When I run that project, it complains about not being able to find a class that exists in the xyz project.
Right click on app , open module settings (F4), Dependencies, Green + and select library file. build.gradle is updated automatically :)

How to add a custom JAR file to CLASSPATH when running gradle from command line?

Same question as this except that, how to do this for Gradle?
I have placed cucumber-android and some other JAR files related to cucumber in my app/libs directory. This is part of my build.gradle:
buildscript {
dependencies {
classpath 'io.fabric.tools:gradle:1.19.2'
classpath fileTree(dir: 'libs', include: '*.jar')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile fileTree(dir: 'libs', include: ['*.jar'])
When I run a cucumber feature test from Android Studio, it runs successfully, because Android Studio automatically includes the files in the libs directory into CLASSPATH.
When I run the test from command line using
./gradlew --info cC
I get the error:
cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
This is because the JAR files in the libs are not in the CLASSPATH. How do I include JAR files when running cc in gradle?
I had to remove the #RunWith(Cucumber.class) annotation from the class that has #CucumberOptions annotation.

Cannot resolve Gradle Android dependency

I am trying to include the HoloColorPicker library (or for that matter any other library in my project), however, I cannot seem to get it to download.
The dependency section in my build.gradle file looks like:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.+'
compile 'com.google.android.gms:play-services-wearable:6.5.+'
compile 'com.android.support:support-v13:21.0.+'
compile 'com.larswerkman:HoloColorPicker:1.5+'
wearApp project(':Wearable')
The error message I get is as follows:
What went wrong: A problem occurred configuring project
':Application'. Could not resolve all dependencies for configuration
':Application:_debugCompile'.
Could not find any version that matches com.larswerkman:HoloColorPicker:1.5+.
Searched in the following locations:
file:/Users/Tom/Library/Android/sdk/extras/android/m2repository/com/larswerkman/HoloColorPicker/maven-metadata.xml
file:/Users/Tom/Library/Android/sdk/extras/android/m2repository/com/larswerkman/HoloColorPicker/
file:/Users/Tom/Library/Android/sdk/extras/google/m2repository/com/larswerkman/HoloColorPicker/maven-metadata.xml
file:/Users/Tom/Library/Android/sdk/extras/google/m2repository/com/larswerkman/HoloColorPicker/
Required by:
watchfaces2.0:Application:unspecified
I cannot seem to figure out why Android Studio is looking for the library under my local path as opposed to pulling the library down from the internet. How can I get past this issue?
Have you included Maven in your gradle file?
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.+'
compile 'com.google.android.gms:play-services-wearable:6.5.+'
compile 'com.android.support:support-v13:21.0.+'
compile 'com.larswerkman:HoloColorPicker:1.5+'
wearApp project(':Wearable')
}
Just for complete the picture:
dependencies {
repositories {
mavenCentral()
}
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.+'
compile 'com.google.android.gms:play-services-wearable:6.5.+'
compile 'com.android.support:support-v13:21.0.+'
compile 'com.larswerkman:HoloColorPicker:1.5+'
wearApp project(':Wearable')
}

Categories