Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Extend existing android app with NativeScript app crash #682

Closed
bsnelder opened this issue Jan 12, 2017 · 5 comments
Closed

Extend existing android app with NativeScript app crash #682

bsnelder opened this issue Jan 12, 2017 · 5 comments
Assignees

Comments

@bsnelder
Copy link

Tell us about the problem

I tried following this guide: https://docs.nativescript.org/angular/integration-with-existing-ios-and-android-apps/extend-existing-android-app-with-ns-angular2.html to proof that we can integrate an existing android/ios application with a nativescript application. For iOS we got this to work, but when following the guide for android I got the application to compile and run om the emulator. However when I click the button to start the NativeScript application using the RuntimeHelper the application crashes.

I get the following error:

I/TNS.Native: NativeScript Runtime Version 2.4.1, commit > b6676b8
D/TNS.Native: JNI_ONLoad
D/TNS.Native: JNI_ONLoad END
D/TNS.Native: Failed to load snapshot: dlopen failed: library "libsnapshot.so" not found
D/TNS.Native: V8 version 5.2.361
D/TNS.Native: lenNodes=66036, lenNames=770833, lenValues=874228
D/TNS.Native: time=1`

After debugging the android application I found out that the problem happens somewhere within the android-runtime.

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.4.1
  • Cross-platform modules: 2.4.4
  • Runtime(s): 2.4.1

Did the error happen while the app was being constructed? (buildtime error)

No

Did the error happen while the app was executing? (runtime error)

Yes, however I don't think it even executes the javascript code yet.

Please tell us how to recreate the issue in as much detail as possible.

  1. Generate a blank Basic Activity android project using Android Studio
  2. Generate a default angular nativescript project: tns create tnsapp --ng
  3. Follow this guide: https://docs.nativescript.org/angular/integration-with-existing-ios-and-android-apps/extend-existing-android-app-with-ns-angular2.html
  4. Run the android application and press the mail button
@slavchev slavchev self-assigned this Jan 12, 2017
@slavchev
Copy link

Hi @bsnelder

The mentioned article is outdated as we currently generate *.dex files for extended classes, as Application, Activity, etc. and these cannot be (easily) consumed from Android Studio, The good news is that for the next release, the one after 2.5, we plan changes in our build process so we will start generating *.java files which will make Android Studio integration much easier.

@bsnelder
Copy link
Author

Hi @slavchev

Thanks for the answer. Good to know that integrating nativescript with Android Studio will be easier from 2.6. Do you have some directions on how to integrate NativeScript within an existing android app with the current release? I know it's probably easier to wait for the 2.6 release but we really want to proof that this is working. I also noticed that the 2.4 changelog contained the following change: "Enable using NativeScript with existing native applications" so wondering what exactly has changed to enable this.

@slavchev
Copy link

I would suggest to wait until the next release, but if it is critical here is a short explanation of what you have to do. You can take a look at <project dir>/platforms/android/build/nativescript-bindings where we generate all the *.dex files. Here is the decompiled NativeScriptActivity.dex code. As you can see it is boilerplate code. You have to set JavaScriptImplementation annotation if the object is instantiated from Java (as in the case of Application, Activity, etc). It is required in order to find the proper overridden method implementation, if any. You have to implement NativeScriptHashCodeProvider, forwarding the calls to Object's hashCode and equals should be sufficient. Finally, you have to forward the actual call arguments to Runtime.callJSMethod.

We follow the above-described process for our test app. You can take a look of NativeScriptActivity.java and MyActivity.js for reference. In any case, manually creating bindings is a tedious process and that's why we provided a tool for that. The following issue #283 might be helpful as well.

@Plamen5kov Plamen5kov assigned Plamen5kov and unassigned slavchev Jan 13, 2017
@Plamen5kov
Copy link
Contributor

Hi @bsnelder,
With this change: ca656f5

Here's a simple implementation of how to integrate NativeScript into a native application. I'll try to update the post, or create a new one if necessary, but until then you can play around and test.

@bsnelder
Copy link
Author

@slavchev Thanks for the explanation!
@Plamen5kov Thanks for the example! Got the integration working now.

Closing the issue

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants