I have a Android app project that depends on a vanilla Java project (':Common'). ':Common' depends on Guava which is located in the Java project's 'lib' directory. The java code in the android project references Guava classes (e.g. the 'Lists' class) as well as classes defined within ':Common'. The compilation of the android project fails due to not being able to find the 'Lists' class but is able to find the classes defined within ':Common' itself. I know this is a configuration that would normally work in a pure Java scenario, but I can't figure out why it fails in this Android case.
NOTE: Adding 'compile fileTree(dir: '../Common/lib', include: ['*.jar'])' to the dependencies of the Android project fixes the compilation error, but obviously this is suboptimal (you shouldn't have to define dependencies in two places like that in gradle).
The build.gradle file for my android project looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {(omitted)}
sourceSets {
main.manifest.srcFile 'AndroidManifest.xml'
main.java.srcDirs = ['src']
main.resources.srcDirs = ['resources']
main.res.srcDirs = ['res']
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile (project(':Common'))
}
The build.gradle file for my java library project (':Common') looks like:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src']
}
dependencies {
compile (fileTree(dir: 'lib', includes: ['*.jar']))
}
A very easy way to solve this problem is to declare guava as a remote dependency of the Common project and have Gradle resolve it at build time. Remote dependencies are transitive and your application would get it by virtue of depending on Common.
Try adding these lines to the build.gradle of the Common project:
dependencies {
compile 'com.google.guava:guava:18.0'
}
Then configure a base repository such as Maven Central:
repositories {
mavenCentral()
}
and remove the guava jar file from the lib/ folder.
Related
I checked all the other threads about this topic but couldn't find an answer.
I am trying to import the Twoway View Project as a library into Android Studio.
Both projects run fine on their own but I always get the same Gradle Error: Error:Configuration with name 'default' not found when trying to import.
I have the project copied into a "libraries" directory in the root folder of my project and the following gradle structure:
settings.gradle of my project:
include ':libraries:twoway-view-master',':app'
build.gradle of "app":
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "app.com.jeldrik.teacherslittlehelper"
minSdkVersion 13
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':libraries:twoway-view-master')
and in twoway-view-master build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
That twowayview-master build.gradle file isn't a buildscript for a standalone module; it lacks any sort of apply plugin statement that would tell Gradle how it should compile something. This looks like the top-level build file of a multimodule-structured project. In your settings.gradle file, you should point at the module in the project you're trying to include, not the build file at the top level.
Did you try it out using File -> New Module?
Or try setting the dependencies from here as well : File -> Project Structure -> Dependencies
I have recently got into same issue. As Scott said we have to include individual modules in our project's build.gradle file. This TwoWayView library has 3 different modules
core
layouts
sample
Say if you want to add core and layouts, add the below lines in your project's build.gradle file (Assuming you have twoway-view-master folder inside libraries folder which is inside your app folder).
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':your-app-folder:libraries:twoway-view-master:core')
compile project(':your-app-folder:libraries:twoway-view-master:layouts')
}
Then add the same path to your project's settings.gradle file
include ':your-app-folder:libraries:twoway-view-master:core'
include ':your-app-folder:libraries:twoway-view-master:layouts'
NOTE: The build.gradle files inside core and layouts have wrong path to gradle-mvn-push.gradle file. So change the path from
apply from: "${rootDir}/gradle/scripts/gradle-mvn-push.gradle"
to
apply from: "${rootDir}/your-app-folder/libraries/twoway-view-master/gradle/scripts/gradle-mvn-push.gradle"
If you still get error in layouts' build.gradle file, change this line
compile project(':core')
to
compile project(':your-app-folder:libraries:twoway-view-master:core')
Do the same change if you're also using sample's build.gradle file in your project.
I found an open source project I wanted to work on but I'm having trouble setting up the initial configuration. The project seems to have been written in Eclipse and I'm trying to get it to work with Android Studio. After being through a number of errors, I'm finally stuck on the following error seen in the configuration menu before I run.
AndroidManifest.XML doesn't exist or has the incorrect root tag
I found a number of answers that suggest like this that suggest I use the sync project with Gradle command but my project wasn't setup with Gradle because I'm building on someone else's project. This is my first time using Android Studio so my following attempt to fix this might not be great. I decided to try to make the project a Gradle project by adding my own build.gradle and settings.gradle files. My layout looks like this:
top level:
inside java folder:
I tried to copy working example of the build and settings Gradle files. My settings.gradle contains the following:
include ':'
My top level build.gradle contains:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//compile project(":")
}
}
allprojects {
repositories {
mavenCentral()
}
}
My java level build.gradle contains:
apply plugin: 'android'
android {
compileSdkVersion 20
buildToolsVersion "17.0.0"
defaultConfig {
applicationId "org.pocketworkstation.pckeyboard"
minSdkVersion 8
targetSdkVersion 19
versionCode 1037
versionName "v1.37"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
jni.srcDirs = ['jni']
}
androidTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And because I think it might be important, my project structure modules:
Trying to synchronize at the moment doesn't generate any word so I assume it's okay but that's a big assumption. Any ideas what I have to change?
Android Studio doesn't consider your project to be a Gradle-based project; you can tell this because a number of the entries you're seeing in the Project Structure dialog don't show up for Gradle-based projects (i.e. the Project, Libraries, Facets, and Artifacts) entries. Close your project and re-import it as a Gradle-based project and you should be okay.
I'm currently downloaded newest android studio 0.3.2. I've been trying to add libraries for almost 5 hours, and nothing.
I've pressed F4 in the 'Module' where the libraries should go, added the libraries, also in the project structure added the dependencies, and also in build.gradle of the 'Module'. The errors in the IDE stop appearing, but when It 'compiles' it. It keeps telling me, that com.google.gson and other libraries don't exist.
How can I fix It? Or should I use Android studio?. Thank you very much.
EDIT
This is the build.gradle file, of the main project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
And this is the Gradle file o f the 'Module' that gives problems:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src']
main.resources.srcDirs = ['src']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
Here is an example for the Google Analytics library and the Gson library:
dependencies {
...
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/libGoogleAnalyticsServices.jar')
}
I'm using Android Studio + gradle on MyProject + Facebook api as a library. See below settings.
I've tried removing all references of support-v4 (either r7 or 18.0.0) and replace them with support-v13, but the message with v4 was still present. I've also noticed that support-v4-r7 appears in External libraries, even though it's not referenced at all, anywhere. Would that be the problem ?
MyProject build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "https://raw.github.com/ark/ark/master/releases/"
}
}
dependencies {
compile 'com.andreabaccega:android-form-edittext:1.0.3'
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile 'com.google.android.gms:play-services:3.1.36'
compile files('libs/imageloader-core-1.5.8.jar')
compile project(':libs:Facebook')
}
android {
compileSdkVersion 17
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'libs/Facebook/src', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
resources.srcDirs = ['build', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
MyProject settings.gradle:
include ':MyProject'
include ':libs:Facebook'
Facebook build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion '18.1'
defaultConfig {
minSdkVersion 8
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'build/source/r/debug', 'build/source/buildConfig/debug']
resources.srcDirs = ['build/source/r/debug', 'build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
Edit: I've tried adding the libs that I use in this project, in another project, one by one, to see what fails. Apparently these 2 are the culprits. If I include any or both of them, I get the above error.
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
Any ideas on how to manage this ?
Edit2: Apparently another project presents the same issue. See build.gradle dependencies below. StickyListHeaders project doesn't contain anymore dependencies. So I presume it's because of ActionBarSherlock ?
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile project(':Project Base:libs:StickyListHeaders')
}
Apparently there were 2 reasons for this issue.
1) PagerSlidingTabStrip library depends on a local support lib v4 jar. Remove the dependency and add the project as a library project in your app and inside it add the maven dependency for support v4. So it should look exactly like the Facebook library project from above.
2) RoboSpice library depends on LRUCache from support lib v4 (https://github.com/octo-online/robospice/issues/195). Just exclude it from your main build.gradle file and you should be good to go.
compile ('com.octo.android.robospice:robospice-spring-android:1.4.7')
{
exclude module: 'support-v4'
}
Hopefully this will help somebody and not spend an entire week with this problem like I did. Oh, and trillion of thanks to #Snicolas. Couldn't have solved it without his help.
Edit: As of RoboSpice v1.4.8, there is no more local support lib dependency, so this issue is fixed.
For anyone who happens to hit this error while using Visual Studio with Xamarin, like I did;
I solved it by simply removing the reference to "Xamarin.Android.Support.v4" from the References folder within the project, then cleaned and built project as normal.
When this is for Xamarin.Android, this error occurs for version mismatching between depended packages. You've got to remove this Xamarin.Android.Support.v4 package from the project along with other mismatching packages. (What does mismatching means here is, if your target Android version is Android 6, all packages listed in the packages.config file should have targetFramework="monoandroid60" packages. If any package won't abide this, it's a mismatching version). If you have messed with versions, then removing the reference and cleaning stuff alone won't work. You've got to remove all the mismatching packages from the Nuget Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages for Solution...). Note that when you're to remove these packages, you'll also need to remove the depended packages. No harm go ahead and remove them all and you can re-install them with the correct version.
Once you've removed the package along with the dependent packages, try building the project. After a successful build, re-install the packages from the Nuget Package Manager with the correct version. (Package versions are listed according to the API levels, Ex: Android 6 which is API 23, would support packages of version 23.x.x)
Cleanup the project and build it, hopefully it'll succeed building!
Hope this'll help cleanup the mess!
Run "gradle androidDependencies" and check your dependencie tree. Add an exclude for the modules that are overlapped.
For example i had to do the following:
dependencies {
compile 'com.google.android:support-v4:r7'
compile project(':libraries:actionbarsherlock')
compile ('com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+') {
// Need to specifically exclude this as it is specified in our own project
exclude module: 'actionbarsherlock'
exclude module: 'support-v4'
}
}
The page slider library also have support library dependency. Thus you are getting this error. In case of maven all you need to do is change your main project pom file dependency entry of the support library to scope as provided.
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>13</version>
<scope>provided</scope>
</dependency>
In case of gradle i think you need to change the dependency configuration to match maven provided scope
Please refer the following link for more details Convert Maven to Gradle
I just got this same issue. I simply updated all Xamarin.Android.Support… nuget packages to the same version.
Note: this app was older so I did not go to the Latest stable version as there were other dependencies that would have needed to be updated. I simply moved them all to the highest common version.
Good luck!
Tom
Remove all old reference .dlls and relevant to that and add again from NuGet.
I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()