Module .so not loaded in apk, but is built - java

I have a project that has an app, and a module that is a library. Both have native c++ code compiled with Cmake.
The app works fine, with all four of the native .so libraries compiling and showing up in the .apk file, but the module is being compiled (it has a .so file in \build\intermediates\cmake\debug\obj), but the .so is not being moved into the .apk with the rest of the libraries. This gives me a java.lang.UnsatisfiedLinkError when I try to run any module code from the app.
Do any of you have any idea what I need to fix for the build to package the .so file from the module?
app build.gradle
plugins {
id 'com.android.application'
}
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdk 32
defaultConfig {
applicationId "com.example.nyota"
minSdk 24
targetSdk 32
versionCode 2
versionName '1.0.1'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ''
}
}
}
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.10.2'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation project(path: ':JavaRTP')
def nav_version = "2.4.1"
def acraVersion = '5.8.4'
implementation "ch.acra:acra-mail:$acraVersion"
implementation "ch.acra:acra-toast:$acraVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Java language implementation
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Feature module Support
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}
module library build.gradle:
plugins {
id 'com.android.library'
}
android {
compileSdk 32
defaultConfig {
minSdk 24
targetSdk 32
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
externalNativeBuild {
cmake {
cppFlags ''
}
}
}
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.10.2'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
My Java class:
package com.active.javartp;
public class RTPPacket {
static {
System.loadLibrary("javartp");
}
public RTPPacket(long handle) {
nativeHandle = handle;
}
public RTPPacket(byte[] data, int size) {
nativeHandle = nativeConstructor(data, size);
}
private native long nativeConstructor(byte[] data, int size);
private long nativeHandle;
}

You need to call loadLibrary in your Java code to load the .so file. Until you do that, the library is unavailable. You also need to make sure the signatures of your Java native functions and the C JNI functions line up properly. Failure to do either will lead to that error. Which you didn't do I can't tell, as you didn't post your C or Java side code.

Related

How to integrate allure report with gradle, junit4 and espresso?

I am trying to generate allure report for android tests, but when I run command .\gradlew clean test, only testcases in test folder are there in the report. there are no tests from androidTest package. is there something wrong in the command or the build.gradle file. I am new to this, not able to figure it out.
I am using Android studio. Attaching build.gradle script.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.qameta.allure.gradle.allure:allure-plugin:2.11.2"
}
}
plugins {
id 'com.android.application'
id "io.qameta.allure" version "2.11.2"
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.tabbedactivity"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "io.qameta.allure.espresso.AllureAndroidRunner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'org.seleniumhq.selenium:selenium-java:4.4.0'
implementation 'io.github.bonigarcia:webdrivermanager:5.3.0'
implementation 'io.qameta.allure:allure-junit4:2.19.0'
}
tasks.withType(Test) {
exclude '**/calltest/Summary.class'
}
Attached the copy of build.gradle file.

Project can't compile after adding admob library

When I add adomb library to my project apps stop working without showing any errurs on android studio. See here.
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.ozayd.azkar"
minSdk 23
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
It's maybe conflict version between your app and admob.
try upgrade admob version :
//with appcompat & material:
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'com.google.android.play:core:1.10.3'
then sync project again.
If it don't work, try add resolutionStrategy in gradle file:
android {
defaultConfig {
configurations.all {
resolutionStrategy {
force 'androidx.appcompat:appcompat:1.5.1'
force 'com.google.android.material:material:1.6.1'
}
}
}
}
then clean project and re sync

Chaquopy How can I import pattern library?

I would like to import pattern library of python.
The build gradle (app) is like below.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.chaquo.python'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.chaquopy"
python{
pip{
install "pattern"
}
}
sourceSets{
main{
python{
srcDirs = ["src/main/python"]
}
}
}
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
// Here is local python.exe folder.
python{
buildPython "C:/Users/xxxx/AppData/Local/Programs/Python/Python38/python.exe"
}
}
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'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Sync task finished successfully,
but it failed when I build the project, because of the failure to install mysqlclient.
Can I import pattern library using Chaquopy?
I'll appreciate your help.
It looks like Pattern doesn't actually require mysqlclient: in fact, it defaults to using SQLite. So you can modify it to remove the requirement:
Download the sdist from https://pypi.org/project/Pattern/#files.
Extract it.
Edit Pattern-3.6/setup.py to remove the "mysqlclient" requirement.
Create a .zip or .tar.gz file from the modified Pattern-3.6 directory.
Install this file by its filename, as shown in the Chaquopy documentation.

Can't implement firebase dependencies on my android app

i'm developing an Android Studio App and trying to create a user register activity. I already added firebase into the project but when i try to add the firebase database dependencies, the app crashes instantly and not a single error is reported. However, when i remove the 3 implements from the build gradle, it runs correctly. Here i leave both build gradle codes. Thanks.
Build gradle project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build gradle app (this works properly):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
}
Build gradle app (this crashes):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-database:20.0.0'
}
SOLVED
The problem just was that i was running an old Android Studio version. I updated Android Studio and checked the gradle versions and now it's all working properly, thanks.
When you use firebase-bom dependency, you no need to mention version for firebase-database and other firebase library.
firebase-bom will choose right version for you or if you want particular version of firebase remove firebase-bom.so add dependency like below
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-database'

Adding API 27 support in Android project producing error

I recently upgraded Android studio and added support for API level 27. Created an emulator for API 27 (pixel xl).
The app runs perfectly fine on Nexus 5X emulator, but fails with following error on Pixel XL emulator. Can someone guide me with right direction?\
Error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.localhost.myapp/com.mycompany.myapp.activity.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp.activity.MainActivity" on path: DexPathList[[zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/base.apk", zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/split_lib_directories_apk.apk", zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/split_lib_resources_apk.apk"],nativeLibraryDirectories=[/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/lib/x86, /system/lib, /vendor/lib]]
Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'io.fabric'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId 'com.localhost.myapp'
minSdkVersion 21
targetSdkVersion 27
versionCode 5
versionName "1.0.3"
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
productFlavors {
localhost {
}
}
applicationVariants.all { variant ->
if (variant.getBuildType().getName() == 'release') {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "proguard"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
}
def flavors = []
new File("app/flavors").eachFile() { file ->
def fileName = file.getName()
if (fileName.endsWith('.gradle')) {
flavors.push(fileName)
}
}
flavors.each { flavorName ->
apply from: rootProject.file("app/flavors/$flavorName")
}
greendao {
schemaVersion 1
targetGenDir "src/main/java"
daoPackage "com.mycompany.myapp.dao"
}
dependencies {
ext {
supportLibVersion = '27.1.0'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':aFileChooser')
implementation "com.android.support:support-compat:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:cardview-v7:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-crash:16.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'
implementation 'com.google.android:flexbox:0.2.6'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'jp.wasabeef:richeditor-android:1.2.2'
implementation 'org.greenrobot:greendao:3.2.2'
implementation 'org.sufficientlysecure:html-textview:3.1'
testImplementation 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
I tried multiDexEnabled true but that did not solve the problem.
After a lot of investigation, I found the "Instant Run" feature is causing the issue. If I disable Instant Run from Android Studio settings, the app is deployed with all source classes.
The side effect is the debugger cannot detect the classes and I cannot debug by placing debug points. If someone has any other solution, I am glad to see that.

Categories