NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
519 stars 135 forks source link

Cannot read property 'extend' of undefined - Android NativeClass #1719

Closed jdnichollsc closed 1 year ago

jdnichollsc commented 1 year ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug

I am the maintainer of the InAppBrowser for NativeScript plugin, and I'm trying to create an instance of a Native class from Android extending the androidx.browser.customtabs.CustomTabsServiceConnection class, but I'm getting this error:

Project successfully built.
Build time: 26.474 s.
The build result is located at: /Users/jdnichollsc/dev/nativescript/nativescript-inappbrowser/demo/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Installing on device 28a99e1c02047ece...
Successfully installed on device with identifier '28a99e1c02047ece'.
Restarting application on device 28a99e1c02047ece...
  JS: [HMR][5ac024c04e98922facdf] boot | HMR Enabled - waiting for changes...
  System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to start activity ComponentInfo{org.nativescript.demo/org.nativescript.demo.MainActivity}: co
  m.tns.NativeScriptException: Calling js method onCreate failed
  System.err: Error: Building UI from XML. @app-root.xml:1:1
  System.err:  > Cannot read property 'extend' of undefined
  System.err:
  System.err: StackTrace:
  System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.demo/org.natives
  cript.demo.MainActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
  System.err: Error: Building UI from XML. @app-root.xml:1:1
  System.err:  > Cannot read property 'extend' of undefined
  System.err:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
  System.err:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
  System.err:   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
  System.err:   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  System.err:   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  System.err:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
  System.err:   at android.os.Handler.dispatchMessage(Handler.java:107)
  System.err:   at android.os.Looper.loop(Looper.java:237)
  System.err:   at android.app.ActivityThread.main(ActivityThread.java:8167)
  System.err:   at java.lang.reflect.Method.invoke(Native Method)
  System.err:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
  System.err:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
  System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed
  System.err: Error: Building UI from XML. @app-root.xml:1:1
  System.err:  > Cannot read property 'extend' of undefined
  System.err:   at com.tns.Runtime.callJSMethodNative(Native Method)
  System.err:   at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
  System.err:   at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1175)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1153)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1149)
  System.err:   at org.nativescript.demo.MainActivity.onCreate(MainActivity.java:52)
  System.err:   at android.app.Activity.performCreate(Activity.java:7963)
  System.err:   at android.app.Activity.performCreate(Activity.java:7952)
  System.err:   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
  System.err:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
  System.err:   ... 11 more
Unable to apply changes on device: 28a99e1c02047ece. Error is: The application org.nativescript.demo does not appear to be running on 28a99e1c02047ece or is not built with debugging enabled. Try starting the application manually..

To Reproduce

Expected behavior Be able to run the demo project and create an instance of a custom Android Native Class here.

Sample project

Please use this repository/commit hash: https://github.com/proyecto26/nativescript-inappbrowser/tree/27fe8f34d68bf04d74817155663fede52267dfef

Additional context

I'm following this other example: https://github.com/sitefinitysteve/nativescript-auth0/blob/master/src/android/provider/customTabsController.ts#L20 I'm not sure if this error is happening since NativeScript 8 with Android 25. Still supporting Android Support, thanks for your help! <3

jcassidyav commented 1 year ago

Try this filter

{
  "uses": [
    "android.app:Activity",
    "android.app:Service",
    "android.content.pm:PackageManager",
    "android.content.pm:ResolveInfo",
    "android.content.res:Resources",
    "android.content:ComponentCallbacks2",
    "android.content:ComponentName",
    "android.content:Context",
    "android.content:Intent",
    "android.content:ServiceConnection",
    "android.graphics:Bitmap",
    "android.graphics:BitmapFactory",
    "android.graphics:BitmapFactory.Options",
    "android.graphics:Color",
    "android.net:Uri",
    "android.nfc:NfcAdapter",
    "android.os:BaseBundle",
    "android.os:Build",
    "android.os:Build.VERSION",
    "android.os:Build.VERSION_CODES",
    "android.os:Bundle",
    "android.os:Parcelable",
    "android.provider:Browser",
    "android.text:TextUtils",
    "android.util:Log",
    "android.view:ContextThemeWrapper",
    "android.view:KeyEvent.Callback",
    "android.view:LayoutInflater.Factory2",
    "android.view:View.OnCreateContextMenuListener",
    "android.view:Window.Callback",
    "androidNative:Array",
    "androidx.browser.customtabs:CustomTabsCallback",
    "androidx.browser.customtabs:CustomTabsClient",
    "androidx.browser.customtabs:CustomTabsIntent",
    "androidx.browser.customtabs:CustomTabsIntent.Builder",
    "androidx.browser.customtabs:CustomTabsService",
    "androidx.browser.customtabs:CustomTabsServiceConnection",
    "androidx.browser.customtabs:CustomTabsSession",
    "androidx.core.graphics:ColorUtils",
    "java.io:Serializable",
    "java.lang:Class",
    "java.lang:Cloneable",
    "java.lang:Long",
    "java.lang:Object",
    "java.lang:Throwable",
    "java.util.regex:Matcher",
    "java.util.regex:Pattern",
    "java.util:AbstractList",
    "java.util:ArrayList",
    "java.util:Arrays",
    "java.util:Collection",
    "java.util:List"
  ]
}
jdnichollsc commented 1 year ago

@jcassidyav it works like a charm, thanks a lot mate! <3