Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

NS 3.0 rc: docs needed on how to migrate NS 2.5 code using native APIs on Android and iOS? #3996

Closed
andy-tai opened this issue Apr 14, 2017 · 12 comments
Labels
Milestone

Comments

@andy-tai
Copy link

andy-tai commented Apr 14, 2017

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

yes, none found

Tell us about the problem

Please, ensure your title is less than 63 characters long and starts with a capital
letter.
no documentation on how to migrate pre-3.0 code using native APIs (Android and iOS) to NS 3.0
Both

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

  • CLI: (run tns --version to fetch it)
    3.0.0-rc1
  • Cross-platform modules: (check the 'version' attribute in the
    node_modules/tns-core-modules/package.json file in your project)
    3.0.0-rc2
  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the
    package.json file of your project)
    3.0.0-rc1
  • Plugin(s): (look for the version number in the package.json file of your
    project)

"nativescript": {
"id": "com.leeco.apollo11.NScreen.nativescript",
"tns-ios": {
"version": "3.0.0-rc.1"
},
"tns-android": {
"version": "3.0.0-rc.1"
}
},
"dependencies": {
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@angular/router": "4.0.0",
"es6-shim": "^0.35.3",
"nativescript-angular": "^2.0.0-rc.1",
"nativescript-couchbase": "^1.0.17",
"nativescript-orientation": "^1.5.5",
"nativescript-theme-core": "~1.0.2",
"nativescript-videoplayer": "^2.4.0",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.2.0",
"serializer.ts": "0.0.12",
"tns-core-modules": "^3.0.0-rc.2",
"zone.js": "~0.8.2"
},
"devDependencies": {
"babel-traverse": "6.23.1",
"babel-types": "6.23.0",
"babylon": "6.16.1",
"lazy": "1.0.11",
"nativescript-dev-android-snapshot": "^0..",
"nativescript-dev-typescript": "^0.4.2",
"tns-platform-declarations": "rc",
"typescript": "^2.2.2"
}
}

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

I have the NS 2.5/Angular project that accesss the native platform APIs on both Android and iOS, following the documentation at
https://docs.nativescript.org/runtimes/android/marshalling/overview.html

and

https://docs.nativescript.org/runtimes/ios/marshalling/Marshalling-Overview.html

and works well. The same code builds with Nativescript 3.0 rc, following the instructions/solutions at
#3928

At the point of accessing native platform APIS from typescript, I get the error messages of

ios:
CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1092:24: ERROR Error: Uncaught (in promise): Error: This value is not a native object.

Android:
JS: ERROR Error: Uncaught (in promise): Error: No java object found on which to call "toString" method. It is possible your Javascript object is not linked with the corresponding Java class. Try passing context(this) to the constructor function.
JS: Error: No java object found on which to call "toString" method. It is possible your Javascript object is not linked with the corresponding Java class. Try passing context(this) to the constructor function.

These indicate some interface change in the native code APIs when accessing from Javascript/Typescript. However, no existing NS 3.0 documentation shows what changes in nativescript code using natve APIs in js/ts needed to upgrade to NS 3.0

@andy-tai andy-tai changed the title NS 3.0 rc: how to migrate NS 2.5 code using native APIs on Android and iOS? NS 3.0 rc: docs neede on how to migrate NS 2.5 code using native APIs on Android and iOS? Apr 14, 2017
@andy-tai andy-tai changed the title NS 3.0 rc: docs neede on how to migrate NS 2.5 code using native APIs on Android and iOS? NS 3.0 rc: docs needed on how to migrate NS 2.5 code using native APIs on Android and iOS? Apr 14, 2017
@dtopuzov dtopuzov added this to the 3.0 milestone Apr 17, 2017
@PetyaSotirova
Copy link
Contributor

Hey @andy-tai could you please share some code that we can use to reproduce this locally? We haven't made any changes in the way native APIs are accessed so there might be something else causing the issue here.

@andy-tai
Copy link
Author

andy-tai commented Apr 22, 2017

OK let me create a simple app to demonstrate the problem

https://github.com/andy-tai/nsrc3apibug

the program works fine on iOS and Android with NS 2.5. The port to NS 3.0 crashes on both Android and iOS

@petekanev
Copy link
Contributor

Hey @andy-tai!

First off, I'd like to reassure you that there are no changes in how native code marshalling works in NativeScript in the upcoming 3.0.0 release.

master and ns_3 branches have an invalid resource in drawable-nodpi/refresh - it's not an image, and the build would naturally fail at merge<flavor, type>Resources build step. It isn't quite clear why you've not copied the original image in the respective directory.

branch ns_3:
After replacing the faulty .png file I was able to successfully build and run your project. No errors were thrown.

JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: page: Page(2) zone: [object Object]
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@b47b4f0
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@8495a69
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on refresh
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@b47b4f0
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@7f8eda1
JS: in AndroidDiscoveryListener onDiscoveryStopped
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on refresh
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@b47b4f0
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@8ea6bc6
JS: in AndroidDiscoveryListener onDiscoveryStopped
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on refresh
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@b47b4f0
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@9ca6787
JS: in AndroidDiscoveryListener onDiscoveryStopped
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on refresh
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@b47b4f0
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@2366b4
JS: in AndroidDiscoveryListener onDiscoveryStopped
JS: in AndroidDiscoveryListener onDiscoveryStarted

branch master:

JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: page: Page(1) zone: [object Object]
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@c364077
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@dc7e4e4
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on refresh
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@c364077
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@918ec7c
JS: in AndroidDiscoveryListener onDiscoveryStopped
JS: in AndroidDiscoveryListener onDiscoveryStarted
JS: on back button
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: page: Page(1) zone: [object Object]
JS: invoke Android's NsdManager
JS: nsd: android.net.nsd.NsdManager@c364077
JS: in AndroidDiscoveryListener constructor
JS: listener: com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__AndroidDiscoveryListener@dc7e4e4
JS: in AndroidDiscoveryListener onDiscoveryStarted

Note: I deleted node_modules, hooks, and platforms between both runs.

I didn't make any particular modifications to any of the files present in the repository, meaning package versions should be as you've left them.

@andy-tai
Copy link
Author

oh,,, ok... I will double check the code on my part. good to know that thing should just work when moving to NS 3.0

@andy-tai
Copy link
Author

@Pip3r4o I double checked the refresh.png in the app/App_Resources/ directory and in the subdirectories of Android and iOS (as symbolic links to the copy in app/App_Resources/) and the image looks valid. (This usage works for me in NS 2.5 although I am not sure if it is officially recommended or discouraged)

As seen from the web browser, https://github.com/andy-tai/nsrc3apibug/blob/master/app/App_Resources/Android/drawable-nodpi/refresh.png is a symbolic link. On Fedora Linux and Ubuntu, I was able to build iOS and Android apps with no problem, on NS 2.5

In any case, I also tried to put the real image (instead of a symbolic link) in the app/App_Resources/Android/drawable-nodpi folder and my Android app still crashes at run time (on the Android emulator). adb logcat output attached

.
logcat.txt

I am not sure what is the difference of my configuration from yours... so I will probably wait for the NS 3.0 release, supposely coming today? (April 26?) and try that.

@petekanev
Copy link
Contributor

@andy-tai

java.lang.RuntimeException: Unable to resume activity {org.nativescript.rc3apibug/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
04-26 06:56:48.162  5546  5546 W System.err: Calling js method onCreateView failed
04-26 06:56:48.162  5546  5546 W System.err: Error: java.lang.Exception: Failed resolving method setUri on class org.nativescript.widgets.ImageView

Is nothing that I've seen before. @tsonevn might have a better idea.

Also - symbolic links - I don't think those work on Windows. I am worried that you may be experiencing the error mentioned above because the actual thing copied is the symlink, and not the image file. Please upload the apk produced in platforms/android/build/outputs/

@andy-tai
Copy link
Author

apk placed inside a zip file uploaded
rc3apibug-debug.apk.zip

@andy-tai
Copy link
Author

I get rid of the symbolic links in another branch ns_3_nosymbollink and on Android the behavior stays the same

@petekanev
Copy link
Contributor

@andy-tai The APK you sent starts up on 4/4 emulator images I fired up, as well as on a physical Android API 21 device.

At this point I am suspecting that the problem is with stale resources somewhere on the device. To confirm my suspicions you could create a new branch where the application has a different name. That will ensure that you won't have stale files that overwrite yours on startup. The problem has since been fixed and is expected to be shipped with 3.0

Please perform the following before running your app again.:

adb shell
cd data/local/tmp
rm -rf org.atai.rc3apibug
exit
tns run android

@andy-tai
Copy link
Author

andy-tai commented Apr 26, 2017 via email

@petekanev
Copy link
Contributor

Closing this as related to NativeScript/android#591

With a workaround available in the issue, and a fix coming in the following release.

@lock
Copy link

lock bot commented Aug 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants