How to solve undefined refrence error on android libtorch? - android-ndk

i got some issue on android libtorch
when i build my project, it always says to "C/C++: C:/Users/Administrator/AndroidStudioProjects/CardFinder/app/src/main/cpp/native-lib.cpp:26: error: undefined reference to 'torch::cuda::is_available()'"
i've never seen that before on visual studio
here's my android studio setting
'Cmake'
cmake_minimum_required(VERSION 3.18)
project(cardfinder)
set(CMAKE_CXX_STANDARD 14)
set(pathInclude ${CMAKE_SOURCE_DIR}/include)
add_library(native-lib SHARED ${CMAKE_SOURCE_DIR}/native-lib.cpp)
file(GLOB OPENCV_INCLUDE_DIRS "${pathInclude}/opencv")
file(GLOB PYTORCH_INCLUDE_DIRS "${pathInclude}/libtorch")
file(GLOB PYTORCH_API_DIRS "${pathInclude}/libtorch/torch/csrc/api/include")
file(GLOB SOURCE_INCLUDE_DIRS "${pathInclude}/source")
file(GLOB LINK_DIRS "${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
include_directories(
${OPENCV_INCLUDE_DIRS}
${PYTORCH_INCLUDE_DIRS}
${PYTORCH_API_DIRS}
${SOURCE_INCLUDE_DIRS})
find_library(
OPENCV_LIBRARY opencv_java4
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(
PYTORCH_LIBRARY pytorch_jni
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(
FBJNI_LIBRARY fbjni
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(log-lib log)
target_link_libraries(
native-lib
${OPENCV_LIBRARY}
${FBJNI_LIBRARY}
${PYTORCH_LIBRARY}
${log-lib}
)
'build.gradle'
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.main.cardfinder"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags '-std=c++14'
}
}
ndkVersion "21.1.6352462"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
def cameraxVersion = "1.1.0-alpha05"
implementation "androidx.camera:camera-core:${cameraxVersion}"
implementation "androidx.camera:camera-camera2:${cameraxVersion}"
implementation "androidx.camera:camera-lifecycle:${cameraxVersion}"
// CameraX View class
implementation 'androidx.camera:camera-view:1.0.0-alpha25'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
'my current project'

Related

Unresolved reference everything when i create new jetpack compose project

i found some broke problem here, this is new project with default sample code I haven't do anything with the code then my android studio looks like in the image
I've try a lot of things including uninstalling android studio and re-installing this android studio, but I still found the same problem
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "id.rizki.nidelist"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}
You're not using the correct dependency versions. Most importantly, you are not using the correct version of Kotlin or Java:
In your project grade file use this:
buildscript {
ext {
compose_version = '1.1.0-beta01'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
}
}
In your app's gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.10'
}
apply from: 'codeinc.gradle'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 31
versionName "1.0"
//def yourVersionCode = getIncrementedVersionCode()
versionCode 1
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
useIR = true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.31'
}
}
dependencies {
def lifecycle_version = '2.4.0'
def activity_version = '1.4.0'
def retrofit_version = "2.9.0"
def paging_version = '3.1.0-beta01'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0-rc01'
implementation 'com.google.android.material:material:1.5.0-alpha05'
implementation "androidx.activity:activity-ktx:$activity_version"
implementation "androidx.activity:activity-compose:$activity_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-rc01"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
}

Unresolved Reference: mockwebserver

I'm writing a test suite with mockwebserver. I entered all of the dependencies from the official github page. Every time I try to run the test I receive Unresolved reference: mockwebserver
There's no option to import. The lettering isn't red on the import. Android Studio doesn't prompt anything. There are no other errors aside from ones related to the unresolved reference.
Screenshot:
build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id("org.jetbrains.kotlin.android.extensions")
}
android {
compileSdk 31
useLibrary("android.test.runner")
useLibrary("android.test.base")
useLibrary("android.test.mock")
defaultConfig {
applicationId "com.example.moviespotter"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
kotlinOptions {
jvmTarget = '1.8'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = '1.8'
}
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
testImplementation 'junit:junit:4.13'
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.10.0' //Glide
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "io.coil-kt:coil-compose:1.3.1"
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
androidTestImplementation 'com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'
}
Since this is in androidTest, it should be
androidTestImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
Also mixing 5.0.0-alpha.2 and 4.3.1 is a world of hurt.
I found the culprit.
When adding the dependency to the build.gradle file it should read implementation.
Change From:
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
To:
implementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr in tid (FinalizerDaemon)

getting this error on switching between two activities containing images and api calls to server and have used glide to load the images. Can any one give suggestions to solve the issue. Has anybody faced such issues ?
Thanks in advance.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
signingConfigs {
config {
keyAlias 'example'
keyPassword 'android'
storeFile file('/home/key/android.jks')
storePassword 'android'
}
}
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.android"
minSdkVersion 15
targetSdkVersion 24
versionCode 26
versionName "2.16"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
debuggable false
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
staging {
minifyEnabled false
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url 'https://maven.google.com'
}
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
// rest api
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.google.android.gms:play-services-maps:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'pub.devrel:easypermissions:0.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile('com.crashlytics.sdk.android:crashlytics:2.6.5#aar') {
transitive = true;
}
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.google.android.gms:play-services-places:10.0.1'
compile 'com.stripe:stripe-android:2.0.0'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support.constraint:constraint-layout-solver:1.0.2'
}
apply plugin: 'com.google.gms.google-services'

Error:Cannot read packageName from E:\Lins\ZXing_luolu\ZxingScan-master\zxing-zxing-3.3.0\src\main\AndroidManifest.xml

.png is my code short cut
I'm failed to Import third-party source libraries
//following are my build.gradle file
//app module
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.meng.zxingscan"
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(':zxing-zxing-3.3.0')
// compile files('libs/core-3.3.0.jar')
}
//zxing module
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.meng.zxingscan"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v7:18.+'
}

Tensorflow in Android, gradle issues

I am trying to get tensorflow in working android, kinda out of default project folder. I modified my build.gradle, but obviously I miss something, as my app crashes on runtime complying about unavailabiltity of native libraries. I have spent good few hours tring to solve this, but to no avail. Could someone help, please?
Basically, i compared .so file in APK produced by working tf demo and my .so, and they are different. So I suppose must me somewhere in my script...
def bazel_location = '/usr/local/bin/bazel'
def tf_location = '/home/poborak/SW/tensorflow-master'
def cpuType = 'armeabi-v7a'
def nativeDir = 'src/main/jniLibs/' + cpuType
project.buildDir = 'gradleBuild'
getProject().setBuildDir('gradleBuild')
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "bazinac.aplikacenahouby"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', tf_location+'/tensorflow/contrib/android/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
jniLibs.srcDirs = ['src/main/jniLibs']
jni.srcDirs = []
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
testCompile 'junit:junit:4.12'
compile 'org.apache.commons:commons-io:1.3.2'
}
task buildNative(type:Exec) {
workingDir tf_location
commandLine bazel_location, 'build', '-c', 'opt', \
'tensorflow/examples/android:tensorflow_native_libs', \
'--crosstool_top=//external:android/crosstool', \
'--cpu=' + cpuType, \
'--host_crosstool_top=#bazel_tools//tools/cpp:toolchain'
}
task copyNativeLibs(type: Copy) {
from(tf_location+'bazel-bin/tensorflow/examples/android') { include '**/*.so' }
into nativeDir
duplicatesStrategy = 'include'
}
copyNativeLibs.dependsOn buildNative
assemble.dependsOn copyNativeLibs
Finally I have found workaround. It is to downgrade Gradle to 2.14.xx and Android Plugin Version 2.1.3. Then I have appended assembleDebug.dependsOn copyNativeLibs and it works now. Still I would be interested in better solution of course. (AssembleDebug property is not recognized in newer APV.

Resources