0

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'
}
Community
  • 1
  • 1
  • There's not enough information here to help you. We need the full Gradle log. You may also refer to [this post](http://stackoverflow.com/questions/36698816/gradle-what-is-a-non-zero-exit-value-and-how-do-i-fix-it) – OneCricketeer May 14 '16 at 13:32
  • You could also use a Gradle dependency instead https://github.com/journeyapps/zxing-android-embedded – OneCricketeer May 14 '16 at 13:37
  • Thank you for the answer @cricket_007. What do you mean by "using a Gradle dependency" ? – Mehdi Hassen Khider May 15 '16 at 12:03
  • The purpose of Gradle is both a build tool and dependency management. When you require a library in your code, you "depend" on it. Click the github link, it tells you what to put in the Gradle file – OneCricketeer May 15 '16 at 12:10
  • I'm using the default ZXing library, so i've tried to add the required dependencies but i still have the same error `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' }` – Mehdi Hassen Khider May 15 '16 at 12:35
  • Please edit your question to include that and the actual text of the stacktrace. You may use the `{}` button to format it if you select the entire text first – OneCricketeer May 15 '16 at 12:38
  • I've successfully used that other library I linked you to, but this question is somewhat a duplicate. http://stackoverflow.com/questions/29513940/how-to-import-zxing-to-android-studio – OneCricketeer May 15 '16 at 12:40
  • I've tried to use the ZXing Android Embedded library. I followed the steps to add the different dependencies. But I still have an error when I try to build the entire project, which is: `Error:(3, 0) Plugin with id 'com.jfrog.bintray' not found. ` – Mehdi Hassen Khider May 15 '16 at 13:25
  • Did you follow the steps on Github? Those are more accurate than an old StackOverflow post – OneCricketeer May 15 '16 at 13:30
  • Though, I am not sure how you managed to reference that as a plugin. Again, if you showed your Gradle files, then that would be useful if you want a definitive answer to the problem – OneCricketeer May 15 '16 at 13:32
  • Ok, I have done this, after creating a new project: * Add "zxing-android-embedded" as a New Module, then I add this `compile project(':zxing-android-embedded')` on the app:build.gradle as a dependency. * Then I followed the steps on Github. They don't specify in which Gradle file we have to add the lines, so I add them to the app Gradle file. I'm actually now on Android Studio, so I'm sure i forgot to do something. – Mehdi Hassen Khider May 15 '16 at 13:44
  • You shouldn't compile the project... You only need to add the dependencies section to your app build.gradle file (because the other one says specifically not to add dependencies there). – OneCricketeer May 15 '16 at 13:47
  • That's what i did. Why should I not compile ? I tried to build with `./gradlew assemble`, but still the same error – Mehdi Hassen Khider May 15 '16 at 13:55
  • I'll tell you once more to please [edit] your question to include all these steps you've taken to get to this error, the text of your Gradle file, as well as the text of the error message – OneCricketeer May 15 '16 at 14:06
  • I added more details of the initial project in the Question post. – Mehdi Hassen Khider May 15 '16 at 14:31
  • You don't need the `repositories { mavenCentral()...}` section. That isn't the correct location of the code anymore – OneCricketeer May 15 '16 at 14:33
  • Here is the project that I was able to get working (not my personal code, but I made it Gradle compatible). I think the Readme is in Chinese, but the code is the important thing. https://github.com/xuxingliu922/DeviceSDK/blob/master/SmartDeviceSDK/build.gradle – OneCricketeer May 15 '16 at 14:37
  • Ok, my bad, I was on the wrong project. – Mehdi Hassen Khider May 15 '16 at 14:38
  • Actually, it would appear the changes I made to that project have been modified, so no guarantees it works anymore. I was really just trying to point out how to use the Gradle dependencies section to include Zxing – OneCricketeer May 15 '16 at 14:51
  • Actually, the only difference between my project and yours is this line `compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'`. How can i replace it on my Gradle file ? – Mehdi Hassen Khider May 15 '16 at 14:55
  • Like I said, not "mine", I just made that code work for someone else here on StackOverflow. And it seems you need to include that line, not replace anything. I still think you shouldn't be compiling that additional project. And just make sure your repositories are all correct. You should only need jCenter. – OneCricketeer May 15 '16 at 15:01
  • If I remeove the ` compile dependency ` from the Gradle file, there'is a error in the initial project – Mehdi Hassen Khider May 15 '16 at 15:28
  • There are so many errors you could be getting. I don't know what you are seeing by saying "there's an error". I'm am sure, though, that you are probably seeing a different message than the one in your initial post – OneCricketeer May 15 '16 at 15:31
  • You were right, I deleted the ` compile project ('android') ` from the Gradle and it seems to build normally. But now, I have an internal error which refers to a class not found ` java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mehdi.qrr/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity" on path: DexPathList[[zip file "/data/app/com.example.mehdi.qrr-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] ` – Mehdi Hassen Khider May 15 '16 at 16:03
  • Did you compile both the embedded and Google Zxing libraries like that link to the project? – OneCricketeer May 15 '16 at 16:06
  • Do I need to compile the embedded library ? I'm not using the Embedded in my first project – Mehdi Hassen Khider May 15 '16 at 16:15
  • Honestly, not sure. All I know is that I was able to run that code without error at one point – OneCricketeer May 15 '16 at 16:17
  • I think i've found the problem. I'm supposed to add the ZXing project as a library. But, it seems like the project is not recognized. How can I add the ZXing project as a library, not as a compilable project ? – Mehdi Hassen Khider May 15 '16 at 16:31
  • And how did you arrive at that? Like I said, you shouldn't need `compile project()` anywhere in your Gradle. You need `compile 'com.google.zxing:core:3.2.1'` instead – OneCricketeer May 15 '16 at 16:35
  • I'm not compiling project anymore, like you've told me. I'm just compiling `compile 'com.google.zxing:core:3.2.1'`. But the error mentionned a class which is in the project, not the library – Mehdi Hassen Khider May 15 '16 at 16:49
  • Now, I'm pretty sure that the problem is the link between my application, and the Barcode Reader application. If i have the reader app already installed, my app works without any problem. But if the reader app isn't installed, my app crashes. I also found an error in my Manifest's app: ` – Mehdi Hassen Khider May 15 '16 at 19:36

0 Answers0