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
Related
I have two gradle . One is project level gradle and another is app level gradle . In app gradle when I add this line, "apply from: "../../../buildCommon/common.gradle"" , then manifest file is lost .
The content of app level gradle is given here :
apply plugin: 'com.android.application'
apply from: "../../../buildCommon/applicationCommon.gradle"
apply from: "../../../buildCommon/common.gradle"
android {
compileSdkVersion 19
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "era.safetynet.payment.apps"
minSdkVersion 14
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':ftrSDKHelperAndroid')
compile 'com.android.support:support-v4:19.1.0'
}
The content of applicationCommon.gradle is as follows :
// ============================================================================
// Main
// ============================================================================
project.ext.productRootDir = "E://Face Verification Application//Neurotec_Latest"
project.ext.productBinDir = new File(project.productRootDir, "Bin")
project.ext.productBinJavaDir = new File(project.productBinDir, "Java")
project.ext.productBinAndroidDir = new File(project.productBinDir, "Android")
project.ext.productLibAndroidDir = new File(project.productRootDir, "Lib/Android")
// ============================================================================
// Android
// ============================================================================
apply plugin: 'com.android.application'
android {
sourceSets {
main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir new File(projectDir, "lib")
}
}
}
The content of common.gradle is as follows :
project.ext.defaultArchitectures = "arm64-v8a,armeabi-v7a,x86"
group = 'com.neurotec.samples'
version = '9.0.0.0'
// ============================================================================
// Android
// ============================================================================
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/resources']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('src/main/tests')
}
packagingOptions {
exclude "META-INF/LE-832C0.RSA"
exclude "META-INF/LE-832C0.SF"
}
lintOptions {
abortOnError false
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
// ============================================================================
// Building
// ============================================================================
// Also delete all project related files from product bin directory.
clean {
delete fileTree(dir: project.productBinAndroidDir , include: "${archivesBaseName}*.*")
}
// Copy data files images to project build directory so thay can be packed in apk.
if (project.hasProperty("ndfFiles")) {
task prepareNdfFiles(type: Copy) {
from "${project.productBinDir}/Data"
includes = project.ndfFiles
rename { String fileName ->
fileName.replace('.ndf', '.ndf.jet')
}
into "${android.sourceSets.main.assets.srcDirs[0]}/data";
}
tasks.preBuild.dependsOn(prepareNdfFiles)
}
// Copy native libraries to project directory so thay can be packed in apk.
if (project.hasProperty("nativeLibsInclude") || project.hasProperty("nativeLibsExclude")) {
if (!project.hasProperty("arch")) {
project.ext.arch = project.defaultArchitectures;
}
int counter = 1;
project.arch.split(',').each {
String srcDir = "${project.productLibAndroidDir}/${it}"
String dstDir = "${projectDir}/lib/${it}"
task "prepareNativeLibs$counter"(type: Copy) {
from srcDir
if (project.hasProperty("nativeLibsInclude")) {
for (String lib : project.nativeLibsInclude) {
include lib;
}
}
if (project.hasProperty("nativeLibsExclude")) {
for (String lib : project.nativeLibsExclude) {
exclude lib;
}
}
into dstDir
}
tasks.preBuild.dependsOn("prepareNativeLibs$counter");
counter++;
}
}
// Copy apk to product bin directory.
task copyApk(type: Copy) {
from "${project.buildDir}/outputs/apk"
include "${project.archivesBaseName}-debug.apk"
rename "${project.archivesBaseName}-debug.apk", "${project.archivesBaseName}.apk"
into project.productBinAndroidDir
}
tasks.build.dependsOn(copyApk)
task deleteTemporaryFiles(type: Delete) {
if (project.hasProperty("ndfFiles")) {
for (String file : project.ndfFiles) {
delete "${android.sourceSets.main.assets.srcDirs[0]}/data/${file}.jet";
}
}
delete "${projectDir}/lib"
}
tasks.copyApk.dependsOn(deleteTemporaryFiles)
// ============================================================================
// Dependencies
// ============================================================================
dependencies {
project.ext.modules = [
"android": "com.google.android:android:4.1.1.4",
"acra": "ch.acra:acra:4.5.0",
]
}
repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs "${project.productBinAndroidDir}/"
}
}
Why is the manifest file lost ? Please help me as I am new in android studio .
I am also getting this error .
Error:Cannot read packageName from E:\Android App Source Code\agent banking\SafetyNetPayment\safetyNetPayment\AndroidManifest.xml
I don't think it is manifest file is lost, It's path is not just defined correctly in the common.gradle file. If i'm not mistaken, your manifest file is in your src\main directory, so the manifest.srcFile should be defined as manifest.srcFile 'src\main\AndroidManifest.xml'.
I have downloaded new Android Studio 2.1 and upgraded my openJDK to version 8.
But I have this issue :
What have I done wrong and what should I do?
Thanks!
added gradl
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:24.0.0-alpha2'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:cardview-v7:23.3.0'
compile files('libs/svgandroid.jar')
compile 'com.android.support:design:23.3.0'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile files('libs/guava-16.0.1.jar')
compile 'com.google.code.gson:gson:2.6.1'
}
// 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 {
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
repositories {
mavenCentral()
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
multiDexEnabled true
}
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']
}
}
See the documentation: http://tools.android.com/tech-docs/configuration/osx-jdk
It involves setting a $STUDIO_JDK environment variable.
Being used to ANT for configuring Android projects in Netbeans, I am new to Android Studio and Gradle.
(In both Netbeans and Android Studio) I am struggling a bit with Gradle dependencies to the last versions of the Android support-v4 library. Everything is fine as long as version is set below 23.0.0, i.e. 22 21 etc, but when using support-v4:23.x.x, things go awry.
To investigate this problem, I have made a minimalist project consisting of one FragmentActivity only. Specifying v4 23, it cannot find any core methods of Activity or FragmentActivity, like e.g. getWindow()
I have tried both mavenCentral() and mavenLocal().
Thanks for any help.
EDIT: The build.gradle content added below.
import org.gradle.api.artifacts.*
apply plugin: 'base' // To add "clean" task to the root project.
subprojects {
apply from: rootProject.file('common.gradle')
}
task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
title = 'All modules'
destinationDir = new File(project.buildDir, 'merged-javadoc')
// Note: The closures below are executed lazily.
source {
subprojects*.sourceSets*.main*.allSource
}
}
buildscript {
repositories {
jcenter()
}
//Make sure that gradle is updated to this version
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
repositories {
mavenLocal()
mavenCentral() //se viktig kommentar 030416
flatDir {dirs 'libs'}
}
apply plugin: 'com.android.application'
ext {
supportLibVersion = '23.2.1'
//versionName = '2.8.0'
}
android {
compileSdkVersion 23
buildToolsVersion = '23.0.3' //"21.1.2"
//publishNonDefault true
defaultConfig {
//minSdkVersion 15 //Spotify requires min14, Facebook min15
//targetSdkVersion 23
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
buildTypes {
debug {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.
replace(".aar", "-${versionName}.aar"))
}
}
}
}
}
dependencies {
//support
compile ('com.android.support:support-v4:23.2.1')
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
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.
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 .