Fields from imported android library not generated in R file - android

I need to integrate a certain SDK with my app, I added the .aar file in my gradle dependencies and I added the code they provided me.
The gradle build went with no special problems, but when I tried to start the SDK's activity the app crashed with the following exception:
12-07 16:28:09.991 16236-16236/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.positiveapps.clickins, PID: 16236
java.lang.NoSuchFieldError: No static field action_show_neura of type I in class Lcom/neura/standalonesdk/R$id; or its superclasses (declaration of 'com.neura.standalonesdk.R$id' appears in /data/app/com.positiveapps.clickins-1/base.apk:classes2.dex)
at com.neura.dashboard.R$id.<clinit>(R.java:995)
at com.neura.dashboard.activity.LoginActivity.onCreate(LoginActivity.java:59)
at com.neura.dashboard.activity.AppAuthenticationActivity.onCreate(AppAuthenticationActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
After I went through the R files that are generated in my application I found out a significant amount of fields that exist in R.txt file in the aar are missing from the generated R.
I've tried building with and without proguard, updating gradle version, I cleaning and rebuilding the project, removing "build" directory manually, adding the aar as a module.
None of these seem to be the problem, the R file is still missing fields.
Thanks for any help, Ilia.

Keep aar file in libs folder. ( as libname.aar )
then in app build.gradle specify following.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'libname', ext:'aar')
}
and click sync project with gradle files.
Then clean build the project.

Related

Resource linking fails on lStar with error

I'm working on a android Native application. My Android builds began to fail without any changes.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':etndoorcontrol:processHesuan_faceDebugResources'.
> Android resource linking failed
C:\Users\xqf\.gradle\caches\transforms-2\files-2.1\fe7b90aa462d9a2e04dd8216aa450a51\res\values\values.xml:2422:5-2449:25: AAPT: error: resource android:attr/lStar not found.
error: failed linking references.
Then I tried 2 solutions
//soultion 1.
configurations.all {
resolutionStrategy {
// Java language implementation
force "androidx.core:core:1.6.0"
// Kotlin
force "androidx.core:core-ktx:1.6.0"
}
}
After I add this to app/build.gradle, the app can build correct.but after I install the apk and run .there is a new problem.
java stacktrace:
java.lang.NoClassDefFoundError: androidx.appcompat.widget.Toolbar
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:163)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88)
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:140)
at com.yarward.a10doorcontrol.homepage.HomePageActivity.initFields(HomePageActivity.java:334)
at com.yarward.base.mvp.view.BaseActivity.onCreate(BaseActivity.java:82)
at com.yarward.a10doorcontrol.homepage.HomePageActivity.onCreate(HomePageActivity.java:257)
at android.app.Activity.performCreate(Activity.java:6709)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2736)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1487)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6157)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: java.lang.ClassNotFoundException: androidx.appcompat.widget.Toolbar
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
... 22 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at java.lang.Class.getDeclaredMethods(Class.java:1812)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:154)
... 18 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.MenuHost" on path: DexPathList[[zip file "/data/app/com.yarward.hesuanface-1/base.apk"],nativeLibraryDirectories=[/data/app/com.yarward.hesuanface-1/lib/arm, /data/app/com.yarward.hesuanface-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 28 more
After this, I tried the other solution, as below:
ext{
androidX = 1.6.0
}
but this is not working for me.
axel8888 thank your sir, yes, I have solved this problem. yes, you are right , when I try solution one again
configurations.all {
resolutionStrategy {
// Java language implementation
force "androidx.core:core:1.6.0"
// Kotlin
force "androidx.core:core-ktx:1.6.0"
}
}
and as you the problem is now in
androidx.appcompat:appcompat:1.4.0-alpha
so I checked the gradle dependencies, yes , even I used
androidx.appcompat:appcompat:1.3.1
but my project shows the version is 1.4.0-alpha. here is my solution
configurations.all {
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == "androidx.appcompat") {
if (requested.name == "appcompat") {
details.useVersion "1.3.1"
}
}
}
}
and it worked, now my project can build and run correctly, thank you, sir!
Obveiously the problem is now in androidx.appcompat:appcompat:1.4.0-alpha. If your UI use Toolbar, you will get the MenuHost not found crash.BUT, evenif I use resolutionStrategy to force 'androidx.appcompat:appcompat:1.3.1', dependency still make it toandroidx.appcompat:appcompat:{strictly 1.4.0-beta01}
It still confuse me a lot.
SOLVED -- someone write a update code for appcompat before... now it can force to 1.3.1 and solve the problem
change
implementation 'androidx.appcompat:appcompat:1.4.0'
to
implementation 'androidx.appcompat:appcompat:1.3.1'
that's it
implementation 'androidx.appcompat:appcompat:1.4.1'
was causing the problem, going back to 1.3.1 worked.
implementation 'androidx.appcompat:appcompat:1.3.1'
ill update once I get an official solution.

Android java.lang.ClassNotFoundException: Didn't find class

I'm a total Android newbie here, so hopefully someone can help me out.
I have an Android library (myLib.aar) that I am including/using in the HelloAR demo app.
Now, I want to use Instacapture within myLib.aar. I followed the instructions on the README:
dependencies {
...
compile "com.github.tarek360:instacapture:2.0.1"
}
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
I also tried downloading, compiling instacapture source, adding the instacapture.aar to my libs dir and modifying my Gradle files:
dependencies{
...
implementation(name:'instacapture', ext:'aar')
}
allprojects {
repositories {
...
flatDir {
dirs 'libs'
}
}
In both cases, I get the following exception:
--------- beginning of crash
2020-08-11 22:34:35.965 32761-32761/com.google.ar.core.examples.java.helloar E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.ar.core.examples.java.helloar, PID: 32761
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/tarek360/instacapture/Instacapture;
at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139)
at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164)
at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171)
at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.tarek360.instacapture.Instacapture" on path: DexPathList[[zip file "/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/lib/arm64, /data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139)
at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164)
at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171)
at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
However, if I add the dependencies to the main HelloAR app (as per the instructions in the README), the issue resolves.
Can someone please explain what is going on, why I'm getting the error, and how to resolve it without having to add the dependencies to the main HelloAR app?
Considering your quote,
I'm a total Android newbie here, so hopefully someone can help me out.
Follow these steps (in android studio) :
Go to build menu.
Clean the project by clicking on clean project.
Build the project by clicking on make project.
This process is known as clean build which is usually done after adding some dependencies.

Failed to load .so in android studio

I wanted to load a .so file: System.loadLibrary("example");
but i faced with this error!!
this is the error:
FATAL EXCEPTION: main
Process: com.name.ex, PID: 30737
java.lang.UnsatisfiedLinkError: dlopen failed: file offset for the library "/data/app/com.name.ex-1/lib/arm/example.so" >= file size: 0 >= 0
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.name.ex.example<clinit>(example.java:582)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newApplication(Instrumentation.java:1020)
at android.app.Instrumentation.newApplication(Instrumentation.java:1005)
at android.app.LoadedApk.makeApplication(LoadedApk.java:670)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1800(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
you might have placed the native assembly for ARM into the wrong directory ...or the file-size is indeed 0. it's ordinary called armeabi-v7a instead of arm, for example (the jniLibs path might need to be adjusted, depending how your project looks alike):
app/src/main/jniLibs/armeabi-v7a
in the module-level build.gradle one can define the location:
android {
...
sourceSets {
main {
jniLibs.srcDir "src/main/jniLibs"
}
}
}

How to build and use PJSIP for different architectures than armeabi?

I succesfully compiled PJSIP library for Android. Sample project works without any problems when I build for default architecture armeabi. Now I tried to compile library for arch such as armeabi-v7a and arm64-v8a. Unfortunately when I add libraries to project in appropriate folders (jnLibs/armeabi-v7a and jniLibs/arm64-v8a) application is not starting...
To setup build for different archs I use this command:
NDK_TOOLCHAIN_VERSION=4.9 TARGET_ABI=armeabi-v7a ./configure-android --use-ndk-cflags
I have this error on app launch:
07-04 12:28:46.079 15317-15317/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.futuremind.omili, PID: 15317
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "getifaddrs" referenced by "/data/app/com.futuremind.omili-1/lib/arm/libpjsua2.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.futuremind.omili.MyApp.<clinit>(MyApp.java:293)
at com.futuremind.omili.MainActivity.onCreate(MainActivity.java:87)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5497)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thanks for any help! :)
I was able to fix this error by updating the AndroidManifest.xml in "pjsip-apps/src/swig/java/android/app/src/main" to match my android target -- in my case to "23". Then "make clean" and another "make" in "pjsip-apps/src/swig", and rebuilding my app.

java.lang.NoClassDefFoundError at Runtime in Activity's inner class

I have found a lot of similar questions, but no one helps me.
I have next problem. I have complete project for Android and I have to export it's functionality to .aar library. First of all I created new project and created new module where put my source project. At this step all things goes well and I get my mylib.aar file in /build/outputs/aar/ folder. Then I created new project to test my mylib.aar, so I created libs folder under my app folder in Android Studio, and in build.gradle file of my test project I added these lines:
repositories {
flatDir {dirs 'libs'}
}
dependencies {
compile(name: 'mylib', ext: 'aar')
}
In manifest file I added declaration of MainActivity from library:
<activity android:name="com.testlib.mylib.MainActivity"
android:label="MainActivity"/>
Android Studio found this file well and I even can watch source code through built-in decompiler. But when I try to start this activity from another activity that isn't placed in my lib I get this error:
3838-3838/com.testapp.testsdkapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.testapp.testsdkapp, PID: 3838
java.lang.NoClassDefFoundError: com.testlib.mylib.MainActivity$RegisterInBackgroundTask
at com.testlib.mylib.MainActivity.registerInBackground(MainActivity.java:1551)
at com.testlib.mylib.MainActivity.onCreate(MainActivity.java:269)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
RegisterInBackgroundTask is inner public AsyncTask class declared in my MainActivity in the library. I tried to put mylib.aar in aar folder and declare in build.gradle in other way, but it didn't help me and I get similar error.
If this information is not enough, I'll add required parts of code etc. So please help me, if you know how to solve my problem! Thanks.
import mylib.aar as module in your project and inside dependencies add following line
compile project(':mylib')

Categories

Resources