My Gradle dependencies includes:
compile'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0
I am getting BUILD FAILED with error:
Error:Execution failed for task ':app:processDebugResources.
Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0
How can I solve this problem?
Use gradle androidDependencies to learn where the duplicate Google Play Services is coming from. Then use exclude to filter the duplicates out in your Gradle dependencies, e.g.
compile('something.that.includes.google.play.services:1.2.3') {
exclude group: 'com.google.android.gms'
}
I had the same problem and I solved by adding this line android.enforceUniquePackageName = false in build.gradle(app) like this:
buildTypes {
release {
...
... ...
}
}
android.enforceUniquePackageName = false
The easiest way is to replace these dependencies by the whole package :
compile 'com.google.android.gms:play-services:8.1.0'
Then you could probably compile it.
OR add android.enforceUniquePackageName = false in your build.gradle.
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 9
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
android.packageBuildConfig = false
android.enforceUniquePackageName = false
}
Related
I have checked that on 2 devices and 1 emu, I can't change the language of my app anymore using localization. even when I do that manually, even when I go back using git to commits where it was tested and working good. The implementation is good, it was working for months but it is not working for debug and release version. It just picked the main language which is English.
I can still change the language from android studio and preview this before running the app, but when I run the app on any device I can't change it anymore.
What I have tried?
running the app on multiple devices
go back to previous commits where it was tested (it was working good, but now not working anymore)
checking the implementation and trying to change that and give that hardcoded values
checking gradle (I am not good with gradle, I think here is the problem)
until now I didn't figure out where is the problem. Can u please tell me what all the reasons that could involved localization in android? I have been working for about a week but I give up, I have to ask now.
here is gradle code (I have undo the changes about lintOptions and still doesn't work)
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.company.app"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '33.0.0'
buildFeatures {
viewBinding true
}
flavorDimensions 'default'
productFlavors {
free {
dimension 'default'
applicationIdSuffix 'free'
}
paid {
dimension 'default'
applicationIdSuffix 'paid'
}
}
sourceSets{
free{
res{
srcDir 'src/free/res'
}
java{
srcDir 'src/free/java'
}
}
paid{
res{
srcDir 'src/paid/res'
}
java{
srcDir 'src/paid/java'
}
}
}
useLibrary 'org.apache.http.legacy'
packagingOptions {
resources {
excludes += ['META-INF/DEPENDENCIES', 'META-INF/NOTICE', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/NOTICE.txt']
}
}
namespace 'com.company.app'
}
dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
def room_version = "2.4.2"
def lifecycle_version = "2.6.0-alpha01"
//room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// viewModelProvider
implementation "androidx.fragment:fragment-ktx:1.5.2"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// google sign in
implementation 'com.google.android.gms:play-services-auth:20.3.0'
// google drive
implementation 'com.google.api-client:google-api-client:2.0.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.3.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0')
}
Java Code
Locale languageToSwitch = new Locale("nl");
Locale.setDefault(languageToSwitch);
Resources res = getBaseContext().getResources();
DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
Configuration config = res.getConfiguration();
config.locale = languageToSwitch;
res.updateConfiguration(config, dm);
recreate();
I tried to invalidate the caches but it didn't work, It is solved after removing the project and android Studio and then cloned it again from github.
If u know why that happens tell me please.
In my react native project I earlier added aws amplify for push notification. After that I wanted to do analytics, so I added firebase to it. After that, my android app build but stops as soon as it launches.
I get error as
java.lang.RuntimeException: Unable to instantiate service
com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService:
java.lang.ClassNotFoundException: Didn't find class
"com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/firebase/messaging/FirebaseMessagingService;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
My app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
packagingOptions {
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
defaultConfig {
applicationId "com.project”
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "1.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
appAuthRedirectScheme: 'com.project’
]
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-firebase')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-reanimated')
implementation project(':#react-native-community_netinfo')
compile project(':react-native-charts-wrapper')
compile project(':rn-fetch-blob')
compile project(':react-native-wheel-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-pdf')
compile project(':react-native-app-auth')
compile project(':#aws-amplify_pushnotification')
implementation (project(':react-native-device-info')){
exclude group: "com.google.android.gms"
exclude group: "com.android.support"
}
implementation project(':react-native-wheel-picker')
implementation project(':react-native-vector-icons')
implementation project(':amazon-cognito-identity-js')
implementation project(':#aws-amplify_pushnotification')
implementation project(':react-native-app-auth')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:16.0.9"
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
//com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
You have to either use compile or implementation, not both. Remove these lines.
compile project(':react-native-wheel-picker')
compile project(':#aws-amplify_pushnotification')
compile project(':react-native-vector-icons')
compile project(':react-native-app-auth')
When you set up AWS Amplify push notifications, you have to first set up a Firebase project that AWS Amplify will hook into.
You can Enable Google Analytics in the Firebase project setup process.
Then include the line implementation 'com.google.firebase:firebase-analytics:17.2.1' in android/app/build.gradle.
I've created a walkthrough for the Firebase setup process for AWS Amplify, containing images for the various steps.
Yesterday my app was building correctly and today without changing anything I'm not able to build anymore, I'm getting this error:
Android dependency 'com.google.android.gms:play-services-stats' has >different version for the compile (16.0.1) and runtime (17.0.0) >classpath. You should manually set the same version via >DependencyResolution
I tried to bypass this with "com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true" and clean the project many times, but the error is still here.
My app/build.gradle file :
apply plugin: "com.android.application"
apply plugin: "com.android.application"
apply plugin: "io.fabric"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.yapero"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
versionCode 743
versionName "1.74"
ndk {
abiFilters "armeabi-v7a", "x86"
}
versionNameSuffix '3'
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
exclude 'META-INF/main.kotlin_module'
exclude 'META-INF/-no-jdk.kotlin_module'
}
dexOptions {
javaMaxHeapSize "4g"
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':#segment_analytics-react-native')
implementation project(':react-native-webview')
implementation project(':react-native-version-check')
implementation project(':react-native-firebase')
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5#aar') {transitive = true}
//implementation project(':react-native-version-check')
implementation project(':react-native-maps')
implementation project(':react-native-intercom')
implementation 'io.intercom.android:intercom-sdk-base:5.+'
implementation 'io.intercom.android:intercom-sdk-fcm:5.+'
implementation project(':react-native-fbsdk')
implementation project(':react-native-device-info')
implementation project(':react-native-appsflyer')
implementation project(':react-native-text-input-reset')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-fast-image')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:16.0.8"
implementation "com.google.firebase:firebase-auth:16.2.1"
implementation "com.google.firebase:firebase-firestore:17.1.5"
implementation "com.google.firebase:firebase-messaging:17.5.0"
implementation 'me.leolin:ShortcutBadger:1.1.21#aar'
implementation 'com.android.support:multidex:1.0.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
My build.gradle:
buildscript {
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.25.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}
Does someone know how to correct or bypass this version check ? Ask me if you need more informations.
This comment on github provides the answer to your question (and mine):
A dependency (react-native-device-info in this case) was using the latest version of one of its dependencies instead of a fixed/pinned version. When a new version of google services was released yesterday, it caused the build to pull in the new version for device-info, thereby causing the conflict with other dependencies that correctly pin the version they need.
The solution is to do what is explained in the linked post in your android/app/build.gradle:
implementation(project(":react-native-device-info"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-gcm:16.0.0"
and possibly replace react-native-device-info with any other dependency that may have the same problem (they would include a line like implementation "com.google.android.gms:play-services-gcm:+" which depends on whatever is the latest version of google gcm).
Add in the file: android/app/build.gradle
android {
...
dependencies {
implementation 'com.google.android.gms:play-services-maps:17.0.0'
}
I'm following a tutorial it worked smoothly at first but some deprecated problems got in. I'm new in programming and I tried some of the solutions that i've read but none of them worked on to solve this problem. I also tried to pasting some code on org.apache.http.legacy which is located on C:\Users\Username\AppData\Local\Android\sdk\platforms\android-23\optional.. BUT i dont know how to open that file so i tried opening it using notepad++.... the code look like this..
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
I also tred adding an extension filename on the useLibrary 'org.apache.http.legacy' .. like useLibrary 'org.apache.http.legacy.jar'
but nothing happened..
And Also changing different classpath like..
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:1.3.0'
Even changin the
compileSdkVersion 23
buildToolsVersion "23.0.2"
And a lot of stuff trying paste, change, delete, cut and replace having some sort of trial and error.. this stuff i made was n a comment because i'm having a rial and error on them..
// compile fileTree(dir: 'libs', include: ['*.jar'])
// compile files('libs/org.apache.http.legacy.jar')
///////////////
//compile 'com.google.http-client:google-http-client-android:+'
//
//compile 'com.google.api-client:google-api-client-android:+'
//
//compile 'com.google.api-client:google-api-client-gson:+'
//
//compile 'com.google.code.gson:gson:2.2.4'
}
//apply plugin: 'com.android.application'
//
//android {
// compileSdkVersion 23
// buildToolsVersion "23.0.2"
//
// defaultConfig {
// applicationId "com.example.--------.-----------"
// minSdkVersion 19
// targetSdkVersion 23
// }
// buildTypes {
// release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
// }
//
//}
//
//dependencies {
//
// compile project(':comtaxibulgariamap_mapsforge_044201406271417533')
// compile fileTree(include: ['*.jar'], dir: 'libs')
//}
build.gradle(Module:app
build.gradle(MyProjectName
I really appreciate any help you can provide.
Try below code, its working fine for me
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "calib.inspectionpro.app"
minSdkVersion 15
targetSdkVersion 23
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 files('libs/commons-lang-2.0.jar')
compile files('libs/commons-io-2.4.jar')
compile 'org.apache.commons:commons-lang3:3.1'
compile 'org.apache.commons:commons-lang3:3.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
I'm trying to add native code to my Android app. NDK worked fine with simple C++ code like "Hello from C++", but I need to use openCV, and I am stuck.
Project build output:
:app:generateArmDebugSources UP-TO-DATE
:app:compileArmDebugJava UP-TO-DATE
:app:compileArmDebugNdk
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::Mat::~Mat():jni_part.cpp(.text._ZN2cv3MatD2Ev+0x3c): error: undefined reference to 'cv::fastFree(void*)'
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::Mat::release():jni_part.cpp(.text._ZN2cv3Mat7releaseEv+0x6c): error: undefined reference to 'cv::Mat::deallocate()'
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::FastFeatureDetector::~FastFeatureDetector():jni_part.cpp(.text._ZN2cv19FastFeatureDetectorD1Ev+0xa0): error: undefined reference to 'cv::FeatureDetector::~FeatureDetector()'
...25+ similar lines...
collect2: ld returned 1 exit status
make.exe: *** [D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/libjni_part.so] Error 1
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileArmDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\android-ndk-r10c\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\Android.mk APP_PLATFORM=android-21 NDK_OUT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj NDK_LIBS_OUT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\lib NDK_DEBUG=1 APP_STL=stlport_static APP_ABI=armeabi-v7a
Error Code:
2
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileArmDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\android-ndk-r10c\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\inter
mediates\ndk\arm\debug\Android.mk APP_PLATFORM=android-21 NDK_OUT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj NDK_LIBS_OUT=D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\lib NDK_DEBUG=1 APP_STL=stlport_static APP_ABI=armeabi-v7a
Error Code:
2
Output:
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::Mat::~Mat():jni_part.cpp(.text._ZN2cv3MatD2Ev+0x3c): error: undefined reference to 'cv::fastFree(void*)'
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::Mat::release():jni_part.cpp(.text._ZN2cv3Mat7releaseEv+0x6c): error: undefined reference to 'cv::Mat::deallocate()'
D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/objs-debug/jni_part/D_\AndroidStudioProjects\OpenCVFeatureDetection\app\src\main\jni\jni_part.o: in function cv::FastFeatureDetector::~FastFeatureDetector():jni_part.cpp(.text._ZN2cv19FastFeatureDetectorD1Ev+0xa0): error: undefined reference to 'cv::FeatureDetector::~FeatureDetector()'
...and 25+ similar lines again...
collect2: ld returned 1 exit status
make.exe: *** [D:\AndroidStudioProjects\OpenCVFeatureDetection\app\build\intermediates\ndk\arm\debug\obj/local/armeabi-v7a/libjni_part.so] Error 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 12.261 secs
I noticed a similar question https://stackoverflow.com/a/22427267/4595220 but I still haven't found a solution. What I am doing wrong?
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.gogiant.opencvfeaturedetection"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "jni_part"
cFlags "-DANDROID_NDK"
ldLibs "log"
stl "stlport_static"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
// make per-variant version code
applicationVariants.all { variant ->
// get the single flavor
def flavorVersion = variant.productFlavors.get(0).versionCode
// set the composite code
variant.mergedFlavor.versionCode = flavorVersion * 1000000 + defaultConfig.versionCode
}
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
// this is the flavor part of the version code.
// It must be higher than the arm one for devices supporting
// both, as x86 is preferred.
versionCode = 3
}
arm {
ndk {
abiFilter "armeabi-v7a"
}
versionCode = 2
}
mips {
ndk {
abiFilter "mips"
}
versionCode = 1
}
fat {
// fat binary, lowest version code to be
// the last option
versionCode = 0
}
}
debug.jniDebuggable true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile project(':libraries:opencv')
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
include D:\OpenCV-2.4.9-android-sdk\sdk\native\jni\OpenCV.mk
LOCAL_C_INCLUDES += D:\AndroidStudioProjects\OpenCVFeatureDetection\libraries\opencv\include
LOCAL_MODULE := jni_part
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_ts libopencv_core
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-8
Project structure: http://i.stack.imgur.com/Yg5Jl.png
Complete project: https://yadi.sk/d/brR5GUjber2Qo
Thanks for any help.
I've tested your project. To make it build successfully, I had to delete the folder app/src/main/jni and the folder app/src/main/3rdparty and the file opencvlibrary-2.4.9.jar in the folder app/libs/. It looks like you have several opencv libs (thus conflicting with each others) in your project.
Hope this helps.
Have you tried to build your project with Eclipse ? I worked a little with OpenCV on Intellij and had some trouble to make it work, it was also a problem of NDK.
The current NDK support in Android Studio and the Android gradle plugin 1.1.0 is limited and deprecated. Auto-generated Makefiles are used on the fly, and linking an external NDK library (like OpenCV) from your NDK sources isn't supported out-of-the-box.
You should remove your ndk{} block inside build.gradle and deactivate the current NDK integration, in order to rely directly on ndk-build and your Makefiles instead. You can also use splits instead of flavors to generate per-ABI APKs, like in this gist: https://gist.github.com/ph0b/9e59058ac59cac104398
Your build.gradle would be like this:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.gogiant.opencvfeaturedetection"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips' //select ABIs to build APKs for
universalApk true //generate an additional APK that contains all the ABIs
}
}
project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile project(':libraries:opencv')
}