I am new to Gradle build system, I have a library project which includes dependencies like Retrofit, okhttp etc.
I compiled my project and created an aar file. I created a dummy project and added my library aar as a dependency.
Now if I don't add Retrofit and okhttp as dependency in my dummy app's build.gradle file, my app crashes with class not found exception.
My Question is : Since the library aar file already includes Retrofit and okhttp as dependency then why do I need to add them explicitly in dummy app's build.gradle file too? Is there a workaround.
Here is my library build.gradle
apply plugin: 'com.android.library'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
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:22.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.android.support:cardview-v7:21.+'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
I was able to resolve this by adding the aar file to a local maven repository. Somehow just adding aar in libs folder and including it as a dependency does not fixes the problem.
If you encounter similar problem just modify your library project build.gradle with these additions
apply plugin: 'maven'
version = "1.0"
group = "com.example.lib"
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
repositories {
mavenLocal()
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
Run the task in the terminal provided in the Android studio itself as ./gradlew uploadArchives
Then in your app module's build.gradle file, add the library as dependency
compile ('com.example.app:ExampleLibrary:1.0#aar') {
transitive = true;
}
Related
I am facing weird issue in Latest support library.
I just migrated my project to the latest Support version provided by GOOGLE and as per google guideline
So the problem is can't find the cardView in latest support file. Is anyone facing this problem ?
here is my App Gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-O'
buildToolsVersion "26.0.0-rc2"
defaultConfig {
applicationId "com.temp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
lintOptions {
disable 'RestrictedApi'
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$support_libs"
compile "com.android.support:design:$support_libs"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'jp.wasabeef:blurry:2.1.1'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android O
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
and here is the project gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.support_libs = '26.0.0-beta1'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I don't see cardview added to dependencies anywhere in your app gradle file. Try adding:
compile 'com.android.support:cardview-v7:25.3.1'
AppCompat v7 don't contain CardView, you need to make the explicit claim of that lib in your dependencies.
So, add compile 'com.android.support:cardview-v7:$support_libs' to your dependencies.
Add these dependencies in gradle file:
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
I saw the sample here to use scala with gradle plugin. I created a new android studio project. These are my gradle builds
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module app build.gradle
apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.ashwinxd.escalaandroidapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile "org.scala-lang:scala-library:2.11.7"
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
compile "org.scalaz:scalaz-core_2.11:7.1.0"
}
The project compiles fine. There is no scala src directory generated. How do I proceed with using scala alongside java files? Is it necessary to use them in a source directory called scala? If so how do I generate it?
You have to create your own src/main/scala directory. That is where the scala gradle plugin looks for the scala source files. Just like the android plugin will look at src/main/java and src/androidTest/java.
That page describes you can customize that directory location at Put scala source files.
In my Android application, I want to add Uber facility to users so that I looked the following library. So that I added the compile 'com.uber.sdk:rides-android:0.1.0' in my main module's (Main application) build.gradle file. It gives me following error when sync the gradele
Failed to resolve: com.uber.sdk:rides-android:0.1.0
I have some other libraries referenced to the application.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.+'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.qapp"
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':facebookSDK')
compile project(':payPalDemo1')
compile project(':uberLibrary')
compile project(':bSLibrary')
compile project(':pullToRefresh')
compile project(':androidmapsutils')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:multidex:1.0.0'
compile files('libs/android-async-http-1.4.6.jar')
compile files('libs/cardio.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/UserFormValidation.jar')
}
Please help me to resolve this exception.
Try to add this in your gradle file
repositories{
maven { url "https://jitpack.io" }
}
In the portion of your build.gradle file that you have included you only have the mavenCentral() repository specified within the buildScript block. In order to make that repository accessible outside of that context you should include a block such as the following to the root level of your build.gradle:
repositories {
mavenCentral()
}
In addition, you have not actually included the line compile 'com.uber.sdk:rides-android:0.1.0' in the file copied in your question.
Ultimately, your build.gradle should include the following:
repositories {
mavenCentral()
}
dependencies {
compile 'com.uber.sdk:rides-android:0.1.0'
}
this SDK is designed to work with Android SDK 16. so minSdkVersion should be 16 or greater
This is my first time to make remote repository. But I am facing some problem in accessing it. Following are my gradle files:
root gradle file
// Top-level build file where you can add configuration options
common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.imagelettericon"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.github.akashandroid90:imageletter:1.0'
}
and each time when I sync the code I am getting same error
Failed to resolve: com.github.akashandroid90:imageletter:1.0
I have follow this and this link to make my repo. But now I am not able to access it in gradle file.
Yo have to change your dependency.
compile 'com.github.akashandroid90:imageletter:1.0' is wrong.
Reading the doc in the github repo you should use.
dependencies {
compile 'com.imageletter:ImageLetterIcon:1.0'
}
However you can check the dependency in the jcenter repo.
Reading the pom file in the repo, I have some doubs about the name.
It should be:
compile 'com.github.akashandroid90:image-letter-icon:1.0'
You can use another way to add a dependency with a github project,using the github repo and the jitpack plugin
In this case you have to add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
In your case it is
compile 'com.github.akashandroid90:ImageLetterIcon:1.0'
More info here.
I'm trying to integrate TestFairy with my project. I use Android Studio 0.8.2 Beta.
Official site: http://testfairy.com/
There is an example how it works: https://github.com/testfairy/testfairy-gradle-plugin
This is my build.gradle:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public';; }
maven { url 'https://www.testfairy.com/maven';; }
}
apply plugin: 'com.android.application'
apply plugin: 'testfairy'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
testfairyConfig {
apiKey "Here is my real api key"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'org.roboguice:roboguice:2.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile 'se.emilsjolander:stickylistheaders:2.3.0'
classpath 'com.testfairy.plugins.gradle:testfairy:1.+'
}
The error I get is:
Error:(6, 0) Plugin with id 'testfairy' not found.
Hot to fix it?
My guess is that you added the TestFairy dependency in the repository closure of you app only. There should be another repositories block for the buildscript, in my project it is in the root gradle file and looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
This lets you define repositories for the build dependencies and app dependencies apart from each other.