Unable to start Chrome CustomTabsIntent in my Android app - java

I am trying to use Chrome Custom Tabs in my Android application. My MainActivity class extends AppCompatActivity. In onCreate, I invoke startCustomTabs. Below is the code for that:
private void startCustomTab(){
CustomTabsIntent intent = new CustomTabsIntent.Builder().setToolbarColor(getResources().getColor(R.color.colorPrimary)).build();
intent.launchUrl(this, Uri.parse("http://github.com/black-dragon/SaavnExtractor"));
}
As soon as the app launches, it crashes with following the error:
11-16 10:55:38.561 30093-30093/com.nick.saavnextractor
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nick.saavnextractor, PID: 30093
java.lang.NoSuchMethodError: No static method
startActivity(Landroid/app/Activity;Landroid/content/Intent;Landroid/os/Bundle;)V
in class Landroid/support/v4/app/ActivityCompat; or its super classes
(declaration of 'android.support.v4.app.ActivityCompat' appears in
/data/data/com.nick.saavnextractor/files/instant-run/dex/slice-com.android.support-support-compat-25.0.0_15c83dd4ec129d2d74bfda2e34f6aeeb93d83fa1-classes.dex)
at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262)
at com.nick.saavnextractor.MainActivity.startCustomTab(MainActivity.java:325)
at com.nick.saavnextractor.MainActivity.onCreate(MainActivity.java:111)
at android.app.Activity.performCreate(Activity.java:6311)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2539)
at android.app.ActivityThread.access$900(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1384)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5507)
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)
Note: If I execute the same code with the same methods in a new app, the Custom Tabs launch fine.

Okay, so here is the resolution. I was using build tools version 25.0.0 but my SDK platform was 24.
Update the build tools, platform tools & SDK to same version and then you won't face this issue.

Along with #Nick's answer, I also had to update the Facebook SDK version and the crash stopped happening.

You need to add Customtabs dependency in your build.gradle file.
implementation 'com.android.support:customtabs:28.0.0'

Related

dlopen failed: cannot locate symbol "_ZN7android10VectorImpl19reservedVectorImpl1Ev"

I need help, cause I'm stucked for 2 days from now and i can't find anything.
I bought device: Kcosit V720 on aliexpress and they send me library with it, but it's so hard to get it work correctly.
While I was trying to load library, i had to download libcamera_client.so, because libbarcodereader.so needed it, so i don't know if it is compatible, but now, I'm receiving another error. Any ideas how to fix it ?:
2020-06-19 09:29:33.056 7239-7239/com.lukas.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lukas.myapplication, PID: 7239
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN7android10VectorImpl19reservedVectorImpl1Ev" referenced by "/data/app/com.lukas.myapplication-1/lib/arm/libbarcodereader.so"...
at java.lang.Runtime.loadLibrary0(Runtime.java:977)
at java.lang.System.loadLibrary(System.java:1530)
at com.lukas.myapplication.MainActivity.<clinit>(MainActivity.java:12)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2616)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
You are most likely missing another .so file. Ensure that all .so files are in the same directory.
The following may help to identify referenced .so files:
https://unix.stackexchange.com/questions/120015/how-to-find-out-the-dynamic-libraries-executables-loads-when-run
Update:
I'm not aware of any android API for this type of hardware. According to https://kcosit.com/kcosit-v720-p1496437.html your device contains most likely a OEM version of the SE4710 barcode scanner, manufactured by Motorola. It seems that there exists an SDK from Motorola but I could only find the corresponding documenation. It is most likely used as base for SDKs provided by OEM licensors. One of such an SDK is available here: https://developer.zebra.com/community/tools
Maybe you are lucky and you can use this SDK also for your device. If it should
also be compatible with your device you would of course also need to check license of the SDK - I haven't found any info yet. Maybe you are able to find a source for the original SDK from Motorolla or an other SDK from an OEM licensor.

How to add operations into Tensorflow Android build

I am trying to run my Tensorflow model on Android, so I am using the nightly native build in here and following the Android demo, I have been successfully get the Tensorflow Android lib running and loaded up the model with below code.
inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);
And the log shows the results are good.
I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
I/TensorFlowInferenceInterface: Model load took 1007ms, TensorFlow version: 1.2.0-rc0
I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/model.pb'
However, when I finished feeding all the input nodes
inferenceInterface.feed("input1", new int[]{1, 2, 3}, 1, 3);
inferenceInterface.feed("input2", new int[]{3}, 1);
inferenceInterface.feed("input3", new int[]{4}, 1);
Then call the run method
inferenceInterface.run(new String[]{"output"});
The Tensorflow is broken saying that some kernels are not registered
E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[input1, input2, input3], outputs:[output]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ...jnitest, PID: 16357
java.lang.RuntimeException: Unable to start activity ComponentInfo{...MainActivity}: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>
[[Node: .../LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>
[[Node: dynamic_seq2seq/decoder/decoder_1/LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at org.tensorflow.Session.run(Native Method)
at org.tensorflow.Session.access$100(Session.java:48)
at org.tensorflow.Session$Runner.runHelper(Session.java:295)
at org.tensorflow.Session$Runner.run(Session.java:245)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:142)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:111)
at ...jnitest.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
.. 9 more
I think the "LessEqual" for int32 should be defined in Tensorflow but just not built along with Tensorflow Android Lib.
So my question is how to include more kernels in the Android lib build or any other way to resolve this, any help will be much appreciated.
I recommending reading this free eBook: Building Mobile Applications with TensorFlow
It has a section on What Ops Are Available on Mobile? (page 33), which explains how to Add the implementation to the build for those op kernels which default to being stripped out for mobile builds.
FYI, the eBook is written by Pete Warden (GitHub, blog), who works at Google and is one of the maintainers of TensorFlow.

Android build variant debug gives java.lang.NoClassDefFoundError

I have been working on a project that has been perfectly fine, until i included the android-smack-xmpp library.
After this inclusion, i am not able to run the app on devices (API < 21) on debug mode. However i am able to run it on release build variant.
Process: com.example, PID: 496
java.lang.NoClassDefFoundError: com.example.network.ServerCalls$3
at com.example.network.ServerCalls.initData(ServerCalls.java:167)
at com.example.ui.fragmentsAndActivities.homeFeed.HomePageActivity.onCreate(HomePageActivity.java:212)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
ServerCalls is included in the HomePageActivity, and compilation works just fine. What is that i could be missing here ?
Also HomePageActivity.java:212 is :
ServerCalls.samosaInitData()
Edit : I have been able to get it working my setting minifyEnabled and shrinkResources to true in gradle for the debug build. This is probably pointing at improper linking in the JVM. But this looks like a hack to me. Can somebody point me to a cleaner way of doing the same?
The error was multi-dexing the solution.
The smack-api library introduction led to the 64k dex limit to be exceeded.
Multidexing the solution does the trick.
It looks like you don't export your library in the final .apk file.
You have to choose the Compile option in your Android Studio project settings in the Dependencies section.

NoClassDefFoundError: com.parse.ParseObject$1

I'm Running into a NoClassDefFoundError on Android 4.4, 4.3, and 4.2. I've tried all day to fix it to no avail. I've tried changing the targetSdkVersion, Parse version, importing the Parse library with a jar instead of Gradle, and cleaning and rebuilding the project. Everything works on Android 5.0 and up.
I'm using Parse version 1.12.0
CompileSdkVersion 23
buildToolsVersion 23.0.2
minSdkVersion 17
targetSdkVersion 23
Here is my stack trace. It crashes on the first attempt to register a subclass of ParseObject.
01-13 12:18:26.500 1347-1347/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.parse.ParseObject$1
at com.parse.ParseObject.<clinit>(ParseObject.java:316)
at com.company.myapp.utils.Application.onCreate(PensterApplication.java:36)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Here is the Application class where it crashes.
I've altered the class names to post online here
public class myApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Parse classes that need registering
ParseObject.registerSubclass(aaa.class); //error happens here
ParseObject.registerSubclass(bbb.class);
ParseObject.registerSubclass(ccc.class);
ParseObject.registerSubclass(ddd.class);
ParseObject.registerSubclass(eee.class);
ParseObject.registerSubclass(fff.class);
ParseObject.registerSubclass(ggg.class);
ParseObject.registerSubclass(hhh.class);
ParseObject.registerSubclass(iii.class);
ParseObject.registerSubclass(jjj.class);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
//set a default acl so that default is not public read.write
if (ParseUser.getCurrentUser() != null) {
ParseACL defaultACL = new ParseACL(ParseUser.getCurrentUser());
defaultACL.setPublicReadAccess(false);
defaultACL.setPublicWriteAccess(false);
ParseACL.setDefaultACL(defaultACL, true);
}
// Save this installation
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseFacebookUtils.initialize(this);
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}
}
Any idea what's going wrong would be much appreciated.
I got some help from the friendly parse people on their github repo.
My issue:
https://github.com/ParsePlatform/Parse-SDK-Android/issues/342
The issue referenced from my issue:
https://github.com/ParsePlatform/Parse-SDK-Android/issues/213
The Stack Overflow Question referenced from the referenced issue. (this is what helped me solve my problem.)
Crash: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout
Turns out it was a problem with multidex. I needed to extend MultiDexApplication instead of Application. I also added a couple things to my proguard rules.
This might be caused by:
aaa (presumably a subclass of ParseObject) having been built with a version of ParseObject that is different than the deployed library version, OR
myApplication being built with a version of ParseObject that is different than the deployed library version.
More likely the latter.

NoClassDefFoundError caught in Android project [duplicate]

Suddenly started receiving this error since a support library update, which crashes the application on launch, even if everything builds fine. I tried to use lower version packages, which gave me the same error. I tried complete reinstall of Xamarin and Android SDK and finally creating a new Project which uses AppCompat but no success.
Android Support Library v22.2
Packages:
Xamarin.Android.Support.v7.AppCompat v22.2
Xamarin.Android.Support.v7.MediaRouter v22.2
Xamarin.Android.Support.v4 v22.2
Xamarin.Android.Support.v13 v22.2
Xamarin.GooglePlayServices v22.2.0.2
Call Stack:
System.Diagnostics.Debugger.Mono_UnhandledException_internal () in
System.Diagnostics.Debugger.Mono_UnhandledException (ex={Java.Lang.NoClassDefFoundError: Exception of type 'Java.Lang.NoClassDefFoundError' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) [0x00084] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.App.Activity.OnCreate (Android.OS.Bundle) [0x00070] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2725
at MyApp.MainActivity.OnCreate (Android.OS.Bundle) [0x0001f] in c:\Users\Admin\Documents\Projects\MyApp\MyApp\Activities\MainActivity.cs:43
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707
at (wrapper dynamic-method) object.e364abe5-1498-42eb-85b3-b3d7986e8b04 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
--- End of managed exception stack trace ---
java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:93)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:77)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:429)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:57)
at md5528fae1ec675c410de183ce65ec994d2.MainActivity.n_onCreate(Native Method)
at md5528fae1ec675c410de183ce65ec994d2.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5333)
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:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
}) in
Android.Runtime.UncaughtExceptionHandler.UncaughtException (thread=, ex=) in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Runtime/UncaughtExceptionHandler.cs:35
Java.Lang.Thread.IUncaughtExceptionHandlerInvoker.n_UncaughtException_Ljava_lang_Thread_Ljava_lang_Throwable_ (Parameters=) in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.Thread.cs:221
object.ce1e54b9-203c-4387-b0fe-be79adb149c0 (Parameters=) in
Today I reinstalled all the support libraries, cleaned and recompiled the app again and the error was gone.

Categories

Resources