I see this link Using ViewPagerIndicator library with Android Studio and Gradle and here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
packagingOptions {
exclude 'AndroidManifest.xml'
}
defaultConfig {
applicationId "com.example"
minSdkVersion 10
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/nineoldandroids-2.4.0.jar')
compile "com.android.support:appcompat-v7:18.0.+"
compile('com.viewpagerindicator:library:2.4.1') {
exclude module: 'support-v4'
}
}
And gradle build has successfully completed .But i can't import com.viewpagerindicator.PageIndicator
.I also check .gradle folder and viewpager folder already exist.Any ideas?
Did you add library in Android Studio by File -> Project structure... -> Libriaries (or Modules)?
Use the full file path to the location of the jar. That's worked for me every time. If you're using Android Studio make sure to 'Sync Project with Gradle Files' and rebuild as well.
Related
According to the Android Espresso documentation to date:
Add Espresso dependencies
To add Espresso dependencies to your project, complete the following steps:
Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
Add the following lines inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile 'com.android.support.test:runner:1.0.0'
I created a new project and the generated app/gradle file was like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
}
When I change it to the following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:26.+'
testCompile 'junit:junit:4.12'
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// Testing-only dependencies
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
I get the following errors:
Error:(29, 24) Failed to resolve: com.android.support.test:runner:1.0.0
Install Repository and sync project
Error:(30, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.0
Install Repository and sync project
I have tried clicking on the "Install repository and sync project" link but nothing happens. I have also tried looking through the SDK manager, but I can't really see anything.
As the solution from comment is solving the problem I am adding it as an answer for others:
Be sure to add Google's maven link to main build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Simply,
Adding google() into allprojects > repositories will do the trick here...
allprojects {
repositories {
google()
jcenter()
}
}
you can downgrade the version, somehow sometimes the targeted version is unavailable from the repo.
use IDE-UI to select the latest version:
Right click on your project folder, select Open Module Settings
search for the package you want in the dependencies, for example
This way, you'll never get an un available version
(of course remember to set proper repo in build.gradle, too)
use these versions
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
I created an Android library named "core" that use the Logger library (https://github.com/orhanobut/logger).
Here its build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
Then I build a .aar of core library.
I add this library as a dependency into my application, by putting the .aarcore files in the libs folder.
That's the build.gradle of my application :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.package.test"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.mypackage:core:1.0#aar'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:multidex:1.0.1'
}
As you can see I have multidex activated.
It compile just fine but at runtime, at the first call to Logger I get an exception:
stack=java.lang.NoClassDefFoundError: Failed resolution of: Lcom/orhanobut/logger/Logger;
Even if I set transitive = true
compile (com.mypackage:core:1.0#aar) {
transitive=true
}
it doesn't work.
Thank you !
I had to do a couple of things in concert to get it to work.
1) In your library project
Add the following to your project-level gradle file:
buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Be sure to use the right version of the plugin for your gradle version, check here.
Add the following to your module-level gradle file:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourPackage'// Doesn't have to be github, just an example
Also in this file, make sure your dependencies (the ones you want to be transitive) use api instead of implementation if you are using Gradle 3.4+. If you are using a version of Gradle <3.4, compile is the way to go. Example:
dependencies {
api 'com.google.android.gms:play-services-location:15.0.1'
}
2) In your app project (which uses the library)
Add the following to your module-level gradle file:
dependencies {
implementation('com.github.YourPackage:yourRepo:version#aar') {
transitive=true
}
}
Add the following to you project-level gradle file (but this will depend on where your library is served from, for me it's jitpack):
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
credentials { username 'yourAuthKey' }// Only for private repositories
}
}
}
Note: You shouldn't add the auth key as a string in build.gradle, put it in a property in your gradle.properties file.
Note 2: JitPack allows you to use for example development-SNAPSHOT as a version number for a gradle dependency. Android Studio caches these dependencies and will not re-download it when you push to your development branch. To overcome this, use commit hashes as version numbers during development or clear (delete) the cache files, located on Windows at ~/.gradle/caches/modules-2/metadata-x.xx/descriptors/com.github.YourPackage/yourRepo. (Needles to say, I learned this the hard way).
Hi all i am using charts library in my project a month ago it was working fine but now i have reinstalled android studio and when i build my project it gives gradle sync error.
Failed to resolve:com.github.PhilJay:MPAndroidChart:v2.1.3
I am stuck on this any suggestions how to solve this.My android studio version is 2.1
Here is project dependencies
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.app.comismv"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
jcenter()
url "https://jitpack.io"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.1.3'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
//compile 'com.cardiomood.android:android-widgets:0.1.1'
}
Thanks in advance
I had the same problem, here is the latest version of MPAndroidChart-v2.2.5.jar jar file.
Just put the MPAndroidChart-v2.2.5.jar inside app/libs/
and add
dependencies {
.
.
compile files('libs/MPAndroidChart-v2.2.5.jar')
}
in gradle file
I have gone through many answers for this question like:
Error :: duplicate files during packaging of APK
Gradle sync fails after adding Firebase dependency: duplicate files during packaging of APK
But still after adding packagingOptions I am getting duplicate file error.
I am working on library and here is my app build gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.mcxiaoke.volley:library:1.0.14'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3')
}
EDIT
Adding packagingOption to my sample where I am adding my library as dependency solves the problem can anyone let me know why I have to add it to my sample build.gradle? Or is there any way to remove from sample.
The error I am getting is:
Gradle 'MyProject' project refresh failed:
Project with path 'libraries:mylibrary_sdk' could not be found in project':myproject'
This is my settings gradle
include ':libraries:mylibrary_sdk',':myproject'
Top level build gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
myproject build gradle
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile project ("libraries:mylibrary_sdk")
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
}
mylibrary_sdk build gradle
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I have read over all the similar answers but I am still stuck on this issue. If I remove compile project ("libraries:mylibrary_sdk") and the libraries:mylibrary_sdk include then myproject builds fine, just without access to mylibrary. The libraries folder is at the same level as settings.gradle, the top level build.gradle and the folder with myproject.
Any help would be appreciated.
This works, adding in answer..it might help someone later
dependencies { compile 'com.android.support:support-v4:19.0.1' compile project (":libraries:mylibrary_sdk") }