I am trying to add a library greenDAO from Github to an Android project created in Android Studio. The content of latest build.gradle created are as follow
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
How to go about doing it?
Any pointer to latest blog on Gradle build system with added help.
GreenDao is on Maven Central (here) so you can reference it in your final dependencies block:
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'de.greenrobot:greendao:1.3.2'
}
Then just reference like you normally would. Android Studio will automatically download the jar file and build it into your app.
Just add compile 'de.greenrobot:greendao-generator:2.1.0' to build.gradle and sync it. You can always check the latest version here.
See this blog post for a step by step greenDAO integration tutorial.
Related
I'm trying to use RomainGuy's ViewServer (https://github.com/romainguy/ViewServer) with my Android Studio project using Gradle, and I can't get it to work.
My understanding is to add a folder in project root ('libraries'), drop the ViewServer directory into it (not the full ViewServer directory but the actual library viewserver folder within ViewServer, and reference it in settings.gradle
include ':VendorSearch'
include ':libraries:ViewServer'
and also in my build.gradle file
compile project(":libraries:ViewServer")
When I do this I get a message that says
Could not find any version that matches com.android.tools.build.gradle:0.5.+
I tried then manually updating build.gradle in ViewServer to use the latest build tools (0.7.+ at the time of posting), but I get the same error with the new gradle version.
Any help and general clarification of how to include non-jar third party libraries would be appreciated!
You probably need to add the repository. Change the gradle.build from:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
I tried to add the support library v4 in a project with android studio, I read how to add the support library
Add support library to Android Studio project
but the tab dependencies not appear. I click on the (only) module of my project, but do not appear. I tried with a blank project nothing appear.
EDIT
Project structure dialog
project
EDIT 2
The build.grade file as generated by Android Studio
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
}
First I recommend you to upgrade the AS to 0.4.0, lot of bugs are fixed in this.
Then check for the dependencies in build.gradle of your MyApplication module for support library.
dependencies {
compile 'com.android.support:support-v4:18.0.+'
}
If not added add the mentioned dependency.
After adding the line sync project with Gradle Files using the option available in toolbar.
Make sure you are not getting any error. If sync happens successfully check the Module again.
You should see screen like this, In my case support v7 also added, you can ignore that.
I'm setting up an Android Studio project. This project has a uses some other libs which are included in the Git repository as submodules. So they have to be in the same root folder. (If this is wrong feel free to write an answer too this would fix me problem too.)
As far I understood gradle the dependencies the have to be in a subdirectory to use the compile project ':subdir:subsubdir' command.
I found something about the include command but I did not get it how to use this, this seems also to require files in any subdirectory. So I digged a little more and found the flatDir command in the scope of repositories but how can I use that?
If helpful or not here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile project('../LibraryProjectName:Library')
compile 'com.examlple.library:Library:1.0'
repositories {
flatDir {
dirs '../LibraryProjectName/Library'
}
}
}
I delt with the same tree hierarchy last week and made a simple sample to get the thing done.
Check out this sample on github.
The key is the use of the settings.gradle files. This sample can be built both from the root directory and from the DummyProject directory.
In Android Studio I'm trying to compile an Android application module which uses an Android library.
The library includes a jar file for Bugsense (included automatically by gradle).
Although the library module compiles correctly, the application module fails because it is looking for the Bugsense jar file that is used within the library module.
I do have a workaround which allows the project to compile. By also including the Bugsense dependency in the project everything works.
My question is: How do I make the project compile without duplicating the Bugsense dependency?
Here is my build.gradle file for the library project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
maven { url 'http://www.bugsense.com/gradle/' }
}
android {
compileSdkVersion 15
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
}
dependencies {
compile 'com.bugsense.trace:bugsense:3.6'
}
The library project is called "util"
Following is the android section of the build.gradle for the application
android {
compileSdkVersion 15
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
dependencies {
compile project(':util')
}
}
When I compile this I get the following error:
* What went wrong:
A problem occurred configuring project ':br'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':br:_DebugCompile'.
> Could not find com.bugsense.trace:bugsense:3.6.
Required by:
dss:br:unspecified > dss:util:unspecified
I can make the compile work by adding Bugsense to the repositories section of the build.gradle file for the application. Following is the code I added to the build.gradle file for the application project.
repositories {
mavenCentral()
maven { url 'http://www.bugsense.com/gradle/' }
}
Remember, the above code is in the build.gradle for the application project AND the library.
How do I avoid adding the Bugsense dependency to both the application and library projects?
UPDATES:
I'm using Gradle 1.8
I'm compiling from the command line with "gradle clean assembleDebug"
The following is the complete build.gradle file for the application project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
//maven { url 'http://www.bugsense.com/gradle/' }
}
android {
compileSdkVersion 15
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
testPackageName "com.myapp.test"
}
dependencies {
compile project(':common')
compile project(':util')
}
}
dependencies {
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.+'
instrumentTestCompile 'com.google.guava:guava:15.0'
}
configurations { spoon }
dependencies { spoon 'com.squareup.spoon:spoon-runner:1.0.5' }
It's the expected behavior. Only the repository declarations for the project whose configuration is currently resolved are taken into account, even when transitive dependencies are involved. Typically, repositories are declared inside the root project's allprojects { .. } or subprojects { ... } block, in which case this problem can never occur.
PS: dependencies { .. } needs to go outside the android { ... } block.
I have two projects. DataModel and my application.
My application starts successfully but then fails with classnotfoundexception. Cant find DataModel project.I used to have the same problem before but I could fix it by updating gradle files although randomly android studio would screw them
DataModel build.gradle
apply plugin: 'java'
MyApplication build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'com.android.support:gridlayout-v7:18.0.0'
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.okhttp:okhttp:1.2.1'
compile 'com.squareup.retrofit:retrofit:1.2.2'
compile project(':DataModel')
}
MyApplication settings.gradle
include ':MyApplication ', ':DataModel'
Have you tried to clean the project? Build--> Clean
There is actually a known issue about something like that, maybe it's enough if you update to 0.3.6.
https://code.google.com/p/android/issues/detail?id=62011