Zxing library integration gradle error in android studio - android

The gradle file content is below
apply plugin: 'com.android.library'
ext.artifactId = 'zxing-android-embedded'
dependencies {
compile project.zxingCore
// Optional dependency.
provided 'com.android.support:support-v4:22.0.0'
}
android {
resourcePrefix 'zxing_'
compileSdkVersion project.androidTargetSdk
buildToolsVersion project.androidBuildTools
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src-orig', 'src']
res.srcDirs = ['res-orig', 'res']
assets.srcDirs = ['assets']
}
}
// This is bad practice - we should fix the warnings instead.
lintOptions {
// Android warns about the he and id locale folders. he -> iw is already handled with a
// symlink. TODO: what about id?
disable 'LocaleFolder'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
It gives error Could not find property 'zxingCore' on project ':zxing-android-embedded'. for the compile project.zxingCore

Add the following dependency to your project build.gradle
dependencies {
compile 'com.google.zxing:core:3.2.1'
}
In my project it works fine.

Related

Use tensorflow lite with Qt

Environment :
OS : Win10 64bits
Qt: 5.12.3
NDK: r18b
JDK: jdk1.8.0_201
I would like to use the tensorflow-lite with Qt5, but there are lots of issues when I try to import the java classes. But how could I download the tensorflow-lite-gpu, tensorflow-lite-cpu and tensorflow-lite-support?
The android studio make this work with 3 lines in the build.gradle, I try to add the 3 lines into the build.gradle too.
dependencies {
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
}
Error messages
At pastebin since it is long
I can build this example by android studio without any issues, how could I use the java api of tensorflow with Qt?
The answer is quite simple, only need to add a few lines into the build.gradle(from QtCreator, projects(alt+x)->other files->build.gradle)
Put following lines in the "android" block of build.gradle
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
aaptOptions {
noCompress "tflite"
}
Change dependencies block(not the one in the buildscript) of the build.gradle to
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
}
This should do the job, the complete build.gradle looks like
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
// Use local TensorFlow library
// implementation 'org.tensorflow:tensorflow-lite-local:0.0.0'
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
aaptOptions {
noCompress "tflite"
}
lintOptions {
abortOnError false
}
}

How do I load the OpenCV Manager package in my Android app?

I am working on Android app which uses OpenCV in Android Studio. My app compiles and executes but when starting the activity which loads OpenCV, I am getting this alert saying
"OpenCV manager package not found. try to install it?"
I click yes, and the Google Play Store app is opened but it can not find the OpenCV Manager. Seems the app is not available anymore in Google Play. However, I would prefer to have the OpenCV library bundled with my app.
Any help is appreciated. Thanks.
Here is my setup:
settings.gradle:
include 'Application', ':libhrdataglasses', ':opencv401'
build.gradle for Application:
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
repositories {
jcenter()
google()
}
dependencies {
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation project(':libhrdataglasses')
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation project(':opencv401')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 26
targetSdkVersion 27
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
}
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']
}
}
build.gradle for opencv401
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
//buildToolsVersion "x.y.z" // not needed since com.android.tools.build:gradle:3.0.0
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
jniLibs.srcDirs = ['../../jni']
java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory
aidl.srcDirs = ['src']
res.srcDirs = ['../opencv401/res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
}
And in my Activity:
#Override
protected void onResume() {
super.onResume();
if (!OpenCVLoader.initDebug()) {
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, mOpenCVLoaderCallback);
} else {
mOpenCVLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
private BaseLoaderCallback mOpenCVLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
mProcessButton.setVisibility(View.VISIBLE);
} break;
default: {
super.onManagerConnected(status);
} break;
}
}
};
1. Include opencv library in your app by downloading opencv sdk and adding this as dependency in your app.
https://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization
2. If you want to use opencv manager then do adb install by getting from this link.
https://docs.opencv.org/2.4/platforms/android/service/doc/UseCases.html#how-to-select-the-proper-version-of-opencv-manager
3. Check the sample code
https://github.com/opencv/opencv/tree/master/samples/android

Gradle sync fails with Dexguard plugin (Android Studio)

I am having a bit of trouble trying to integrate dexguard to my android/gradle project.
Dexguard: 5.5.32
gradle: 2.2.1
gradle-plugin: 1.3.0
buildToolsVersion: 23.0.1
I get the following error when I apply plugin: 'dexguard':
Error:Unable to load class 'com.android.builder.SdkParser'
EDIT:
Here is my app's gradle file:
buildscript {
repositories {
flatDir { dirs '/usr/local/DexGuard5.5.32/lib' }
jcenter()
}
dependencies {
classpath ':dexguard:'
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'dexguard' //This, when uncommented produces the error
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile files('libs/commons-collections4-4.0.jar')
compile files('libs/commons-codec-1.10.jar')
compile files('libs/gson-2.3.1.jar')
compile files('libs/jaxb2-maven-plugin:2.1.jar')
compile project(':sdk')
compile project(':zxing-lib')
}
android {
signingConfigs {
release {
//my signing config
}
}
compileSdkVersion 22
buildToolsVersion '23.0.1'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src/main/native', 'src/test/java']
resources.srcDirs = ['src/main/java', 'src/main/native', 'src/test/java']
aidl.srcDirs = ['src/main/java', 'src/main/native', 'src/test/java']
renderscript.srcDirs = ['src/main/java', 'src/main/native', 'src/test/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
//The following should be uncommented when dexuard works!!!
// debug {
// proguardFile plugin.getDefaultDexGuardFile('dexguard-debug.pro')
// proguardFile 'dexguard-project.txt'
// proguardFile 'dexguard-project-debug.txt'
// proguardFile 'proguard-project.txt'
// }
// release {
// proguardFile plugin.getDefaultDexGuardFile('dexguard-release.pro')
// proguardFile 'dexguard-project.txt'
// proguardFile 'dexguard-project-release.txt'
// proguardFile 'proguard-project.txt'
// }
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
}
defaultConfig {
targetSdkVersion 22
signingConfig signingConfigs.release
}
productFlavors {
app2 {
applicationId "some.app.id"
}
app {
applicationId "some.app.id2"
}
}
}
What are your thoughts ??
Your DexGuard plugin looks terribly outdated. The latest version, according to the GuardSquare website, is 7.0.22.
Upgrading is kind of mandatory, since version 7.x brought compatibility with gradle-plugin 1.3.x and build-tools 23.x.
Whats your Logcat Throws
Error:Unable to load class 'com.android.builder.SdkParser'
Cause
This problem is caused by android gradle plugin does not match for
gradle version.
Courtesy
Actually you are using old version DexGuard5.5.32 .That's why have problem . Use latest version of Dexguard & latest SDK and gradle plugins .
DexGuard 6.0 released
This section takes you through the steps of hardening your application
with DexGuard, from making sure the communication is secure, all the
way to encrypting strings and classes.
And upgrade your tools.build:gradle version for better approach .
dependencies {
classpath ':dexguard:'
classpath 'com.android.tools.build:gradle:1.4.0-beta2'
}
Regards
You can set compileSdkVersion 23 instead of 22 .
Try this way .I hope it will helps you .

Is this a Module, Sub-Project, Library Project or something else?

I am trying to install Android-GPU-Image in my project. https://github.com/CyberAgent/android-gpuimage
When I download the source, it's broken down as such:
The github project does not include install instructions (other than a dependency line that didn't work for me) so I am trying to figure out how to install a package like this.
My question is: What is the general name of this 'android-gpuimage' folder in the context of adding it to a project? Is this a Module, Sub-Project, Library-Project or what?
Update
Here is my gradle file
import java.util.regex.Pattern
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
project.ext {
multiarch = false
compileSdkVersion = Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
minSdkVersion = Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion = Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
buildToolsVersion = project.ANDROID_BUILD_TOOLS_VERSION
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
compile project(':CordovaLib')
compile project(':app-FacebookLib')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/twitter4j-core-4.0.3.jar')
compile files('libs/twitter4j-core-4.0.4-SNAPSHOT.jar')
compile files('libs/Filters.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
}
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
def getVersionCodeFromManifest() {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return Integer.parseInt(matcher.group(1))
}
Answer:
Needed to add
repositories {
mavenCentral()
}
To my gradle, the one I already had was in the build script, I needed it outside that scope too.
https://stackoverflow.com/a/16675271/3324388
What you have checked out of github is the entire project , which containes the library project and a sample project showing how to use the library.
To use the library , you would have to include the dependency in gradle as mentioned
dependencies {
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
}
The gradle file lets you know what kind of project it is
for example ,a library project would have
apply plugin: 'com.android.library'
and the main application project would have
apply plugin: 'com.android.application'

Top Level Exception - Android Studio

I have been getting Top level exception in android studio, i am using appcompat and sliding menu library. I know i am getting the exception because of conflict of Android Support Libraries as explained in some of the previous threads in stackoverflow. I have tried All the the methods shown in threads like including configuraion etc.
here is my Build.gradle(root)
// 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.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}
allprojects {
repositories {
jcenter()
}
}
Here is my Build.Gradle(App)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
applicationId "com.danaraddi.cprograms"
minSdkVersion 8
targetSdkVersion 21
versionCode 9
versionName "7.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
}
// animations
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.0.8#aar'
}
// inject views
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.jakewharton:butterknife:5.1.2'
}
dependencies {
// Your other dependencies go here
compile project(':library')
}
Here is my Build.Gradle(Lib - SlidingMenu)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
Here is my Log Cat
Error:Execution failed for task ':app:dexDebug'.
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
PS : I Have places configuration in root,app build.gradle too , it builds successfully after a clean project and then after the same error.
Add
dexOptions {
preDexLibraries = false
}
instead of
dexOptions {
incremental true
}
to build.gradle file inside the android block

Categories

Resources