Hi I'm new in android development and in JAVA. I have Android studio and a new project. I added to my project one dependency on library from maven repository in project properties. So if for example after one year someone will update this library in maven repository, I will need update also link to this library in project settings, or it will load new version of library automatically? Thanks.
Here my .gradle configuration:
apply plugin: 'com.android.library'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.robbypond:mopub-android-sdk:3.2.2d'
compile 'com.googlecode.android-query:android-query:0.25.9'
}
As long as you define your dependency to a fixed version (such as com.robbypond:mopub-android-sdk:3.2.2d), the dependency will not be updated. There will simply be no update of the dependency, since after a dependency is released, its contents should be fixed.
If you want to 'automatically upgrade' to a newer version, you might want to use a 'dynamic version'. You can do that like so:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.robbypond:mopub-android-sdk:3.2.+' // note the + instead of 2d
compile 'com.googlecode.android-query:android-query:0.25.+' // note + instead of 9
}
The advantage is that you can get a newer version of the library only if the last part of the version number changes. When the library author adheres to semantic versioning, you'll only get bugfix updates but never introduce compile failures due to a changed API.
Another option is to leave out the version number at all. This introduces the risk of getting newer version of an API, possibly breaking your build. I'm mentioning it for completeness only:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.robbypond:mopub-android-sdk' // note the missing :3.2.2d
compile 'com.googlecode.android-query:android-query' // note the missing :0.25.9
}
Related
My goal is to distribute an .aar file that can be used by other developers in their projects. The problem I find is when i try integrate my .aar into other project, is i need specify all of the dependencies in their build.gradle file that I have already included in my .aar build.gradle.
My question it if possible only include my library as a dependency and somehow the libraries that my library depends on will get included in the other project.
For example, my library defines the following dependencies in its build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
}
I wrote a test app that uses my library and add like module in Android Studio interface
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile project(':myLibrary')
}
However, this does not work. I get java.lang.VerifyErrors at runtime. What ends up working is to include this in the app's build.gradle file:
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
compile project(':myLibrary')
}
Why do I need to include dependencies in both the .aar and the final application? What am I not understanding about how dependencies work? Why isn't the final application able to grab the .aar's dependencies from maven or jCenter at build time?
I am a newbee in Gradle. I have a simple project structure (shown bellow) having a main android app module, one android module (myandroidlibrary), and one pure java module (myjavalibrary). They have simple dependencies, app -> myjavalibary, and myjavalibary -> myandroidlibrary (pls see fig. below). Gradle files snapshots are also given below.
However, while sync the gradle it produces following error:
D:\MyTestCodes\MyTestApplication\app\build.gradle
Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar
Pls help me out! I have spent this whole day to sort it out with no result!
MyProject
- app
- myjavalibrary (pure java library)
- myandroidlibrary (android library)
Now the dependency is as follows:
"app" depends on -> "myjavalibrary"
"myjavalibrary" depends on -> "myandroidlibrary"
Gradle files for each of the modules are as follows:
build.gradle for app:
apply plugin: 'com.android.application'
android {
// ommitting other detail
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':myjavalibrary')
}
build.gradle for myjavalibrary:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':myandroidlibrary')
}
build.gradle for myandroidlibrary:
apply plugin: 'com.android.application'
android {
//ommiting other detail.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
settings.gradle:
include ':app', ':myjavalibrary', ':myandroidlibrary'
Now while I sync the gradle files it shows the following error:
D:\MyTestCodes\MyTestApplication\app\build.gradle
Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar
Warning is caused by pure-jave myjavalibrary module having a dependency on the myandroidlibrary one, which is an Android library.
Gradle warns you that a pure-java module doesn't know anything about Android specific stuff of myandroidlibrary (like Android resources, assets etc.). By having this dependency (pure-java to android library one) you might lose some stuff you expect to have.
A much cleaner dependency direction would be the one from a android library to a pure-java library. In this case Gradle won't give you any warnings.
If you want to create an Android app project from java code, use apply plugin: 'com.android.application'.
If you want to create a library project from java code, use apply plugin: 'com.android.library'.
If you want to use pre-built jar files, do not create any project for them. Just add them into the projects, into the libs folder, which depend on them. The compile fileTree(dir: 'libs', include: ['*.jar']) in the dependencies would take care of them.
Note: I am not very familiar with gradle
Several projects I've worked on with gradle have a dependencies section such as the following where I used the Sugar ORM:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.github.satyan:sugar:1.3'
}
I can compile the Sugar ORM project using:
'com.github.satyan:sugar:1.3'
I have a local server hosting a small library on GitLab which I want to include in my next gradle project.
I want to be able to do the following in my dependencies section for my new project:
dependencies {
compile 'git.devstuff.com:?:?'
}
http://git.devstuff.com/admin/broadcast_lib.git (local server) is the where my git project is, but I don't know how to fill in the question marks in the above code snippet.
The end result I would like is to include the library in a future project via the following in my build.gradle file:
dependencies {
compile 'git.devstuff.com:broadcast_lib:1.0'
}
I'll update the question if I'm lacking information.
I'm just a hobbyist programmer trying to access Google Calendar. I'm using Android Studio. I've downloaded all the Google Services from the Android SDK manager and set the dependencies. I've also tried following all of Google's documentation of how to do this here: Google Developers: Calendar API Client Library for Java, by adding the client libraries manually in the libs folder of the project.
Any time I do any of this the sample scripts say to type:
import com.google.api.etc...
No matter which way I do it "api" always gets highlighted in red and says it cannot be resolved. I have access to drive, maps, and a bunch of other google stuff, just not calendar.
Has anyone else experienced this problem? If so, how did you fix it? If you need more information from me I'd be happy to supply it.
Thanks!
This is what my build.Gradle dependencies currently looks like:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:+'
}
Print here code of your files Gradle.
You need it likes here, and put it into file build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
UPDATE:
Easify method for adding library, then you can put it into file build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-calendar:v3-rev84-1.18.0-rc'
}
Given a build.gradle that has dependencies like these:
dependencies {
compile fileTree(dir: 'myLegacyLibsNotYetConverted/lib', include: '*.jar')
compile fileTree(dir: 'myOtherLegacyLibsNotYetConverted/lib', include: '*.jar')
compile 'org.springframework:spring-tx:3.1.2.RELEASE'
compile 'org.springframework:spring-jms:3.1.2.RELEASE'
compile 'org.springframework:spring-jdbc:3.1.2.RELEASE'
(...)
testCompile "junit:junit:4.11"
testCompile fileTree(dir: "legacyBuild/test-lib", include: "*.jar")
(...)
providedCompile "javax.servlet:servlet-api:2.5"
providedCompile "javax.servlet.jsp:jsp-api:2.2"
}
What is the easiest/recommended way to add them to the IntelliJ's IDE's classpath so that all my interactive compiler and tests have all the class dependencies they need? Is it possible to sync it every time it changes?
A flexible solution that could work in Eclipse with minor changes would be much appreciated too.
Assuming you've got Gradle plugin installed(Preferences>Plugins>Install JetBrains plugin>Gradle), using IntelliJ 12, just clicking on Refresh Gradle Project should put all dependencies in your classpath.
The easiest solution is to use the IDE plugins. IntelliJ 13 (EAP) ships with great out-of-the-box support for Gradle. (I don't recommend to use the IntelliJ 12 JetGradle plugin as it's too limited.) For Eclipse there is the Eclipse Gradle Tooling. Both plugins will resync dependencies at the push of a button.
The other approach is to use the eclipse/idea Gradle plugins and (re)generate IDE project files whenever necessary. This approach is documented in the Gradle User Guide.