I'm trying to build a project with the ZXing library. I used the instructions in this post to integrate the library into my Android project and I believe I have done that successfully. However, when I try to build the entire project, there is an error in the Gradle build that refers to a dependency or something similar. However, I think I've already solved all the issues with dependencies.
The returned error in Gradle :
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:prepareDebugDependencies'.
The message is
Dependency QRR:android:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency.
Here is the full Gradle log using Stacktrace.
EDIT:
In this project, I used the full ZXing library, not the Embedded or the Minimal.
After the download of the full repo of ZXing here, I've added the android folder as a new Module of the project. I've added the dependency on the Gradle file. Then, I've dowloaded the core on the Maven repo, then I imported it as JAR Library. I've added the dependency in the android:build-gradle.
The app:build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.mehdi.qrr"
minSdkVersion 15
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')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':android')
compile 'com.google.zxing:core:3.2.1'
}
repositories {
jcenter()
}
The Project:build-gradle is:
// 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.5.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
}
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/journeyapps/maven"
}
}
The android:build-gradle (Gradle file of the ZXing project):
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 21
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.google.zxing.client.android"
minSdkVersion 15
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.zxing:core:3.2.1'
}
Related
I'm using Android Studio 2.1.2 and it is giving error "Error:(29, 17) Failed to resolve: junit:junit:4.12" Similar error for any third party library. I have tried removing and adding the junit library from Project Settings but still it giving same error. I'm not sure whether this proxy issue? I have checked connection from Studio for maven link and it is showing successful. Following is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 17
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.0.0'
}
Project Level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
repositories {
jcenter()
mavenCentral()
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Please let me know if I'm missing something and how to resolve this.
After lot of efforts I was able to resolve this issue. Issue lies with the proxy settings, I have added following lines in gradle.properties file and gradle synced successfully with dependencies resolved
systemProp.http.proxyHost=x.x.x.x
systemProp.https.proxyPort=xxxx
systemProp.https.proxyHost=x.x.x.x
systemProp.http.proxyPort=xxxx
I'm having a problem importing com.google.gson using Maven. Right now, I'm getting the following errors:
Error:(24, 17) Failed to resolve: junit:junit:4.12
and
Error:(22, 13) Failed to resolve: com.google.code.gson:gson:2.5
Here is the build.gradle for the Project:
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
repositories {
jcenter()
mavenCentral()
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and here is the build.gradle for the "Module: App":
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.name.testversion"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.5'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
}
Please tell me what to do to fix these problems and successfully import "com.google.code.gson:gson:2.5" into Android Studio to use with this project.
Also, just so you know, I'm newer to Android Studio, just to put that into perspective, and this is my first time using Maven in Android Studio, but not first time using Maven in general.
Change your project gradle to this one
//Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
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
}
On your Project build.grade try using:
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Instead of just repositories {...}
I'm new to Android and I can't get my first app to run. Whenever I try, it's throwing this error:
Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.
I googled it and I found many questions there. As many said, this problem is probably due to the fact that I have multiple dependencies on BouncyCastle in my project. I tryed to remove the .gradle folder both in my project and in my local folder so I could download again the jars from the repository but nothing has changed. I also double checked that my JAVA_HOME is set and it's pointing to a 1.7 version. I tryed to gradle :app:clean and gradle :app:dependencies to see if I was missing something but still... I can't see any dependency from BouncyCastle... Can anybody help me?
Also, this problem occured without me changing any code... The app successfully worked yesterday and now is giving me this error... I don't get it. Thank you.
EDIT
gradle.build
Top-level:
// 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.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.aurasphere.provaactionbar"
minSdkVersion 11
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:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile project(':volley')
compile files('libs/gson-2.2.2.jar')
}
Module volley:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion = '21.1.0'
}
apply from: 'rules.gradle'
rules.gradle for module volley:
apply plugin: 'com.android.library'
I've solved this problem myself just by changing the JDK I was using from x32 to x64 and now is compiling correctly.
I have tried to import multiple libary for project in android studio.But it always shows error like
For this, I tried multiple solution like sdk update , studio update , build.gradle update and so on.Eventhough, i could not get any result.anyone give solution please.
Herewith I mentioned my gradle sepcification too.
app - build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.abof.android"
minSdkVersion 17
targetSdkVersion 21
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.google.android.gms:play-services:7.5.0'
compile files('libs/volley.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':libraries:facebookV2')
compile files('libs/httpcore-4.3-beta1.jar')
compile files('libs/httpmime-4.3.5.jar')
compile project(':libraries:gson-2.2.4')
compile project(':libraries:citruslibrary')
}
project - build.gradle
// 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.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I am building an Android library with Gradle and I have a compile time only dependency.
I am using Gradle 0.9+ so if I do
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
it works and libA.jar is not packaged in my final aar.
However, if I turn ProGuard to on, this does not work and libA.jar is getting packaged.
I have also excluded this jar from obfuscation by adding
-keep class com.libA.** { *; }
to my proguard-rules.txt but it doesn't make any difference.
I can see that the proguardRelease task gets executed before all the packageRelease tasks, however I am not really sure if I can do anything.
This is my whole build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
}
Is there any way to compile against a jar but exclude it from the final package without having to turn ProGuard off?
I just recently came back to this and found a workaround, so I thought I would share:
I am now adding the 'libs' folder as a local repository, so my build file looks something like that (I have also updated the Gradle version):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile ':libA'
compile 'com.android.support:support-v4:20.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
The dependency is resolved fine and is not packaged in the final aar.
Also, I am not including anything extra in the proguard file.