Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Nativescript 4.1.0 using custom main activity with webpack #559

Closed
tsonevn opened this issue Jun 8, 2018 · 57 comments
Closed

Nativescript 4.1.0 using custom main activity with webpack #559

tsonevn opened this issue Jun 8, 2018 · 57 comments

Comments

@tsonevn
Copy link

tsonevn commented Jun 8, 2018

From @RadouaneRoufid on June 7, 2018 21:11

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

Tell us about the problem

I'm using a custom MainActivity declared as below in my nativescript project in a file named MainActivity.js. I'm importing this file in my vendor-platform.android.ts and declare this activity as my MainActivity in AndroidManifest.xml as <activity android:name="org.bricool.MainActivity"....

I updated recently my project from tns 4.0.0 to tns 4.1.0 and nativescript-dev-webpack from 0.10.1 to 0.12.0. When I start the ns app in dev mode (tns run android). The app works fine, but when I build a release bundled, aoted, uglified and snapshoted, the build succeed but tns does not find the MainActivity on start.

@JavaProxy('org.bricool.MainActivity')
export class Activity extends android.support.v7.app.AppCompatActivity {
...
}

I solved this problem in the previous version of nativescript by doing the following in the webpack.config.js

entry: {
            bundle: aot ?
                `./${nsWebpack.getAotEntryModule(appFullPath)}` :
                `./${nsWebpack.getEntryModule(appFullPath)}`,
            vendor: "./vendor",
            [mainSheet]: `./${mainSheet}`,
            MainActivity: "./MainActivity"
        },

I tried the following with the last version of dev-webpack but it does not work.

entry: {
            bundle: entryPath,
MainActivity: "./MainActivity"
        },

Which platform(s) does your issue occur on?

Android

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

  • CLI: 4.1.0
  • Cross-platform modules: "[email protected]",
  • Runtime(s): tns-android 4.1.2
  • Plugin(s):
    "dependencies": {
    "@angular/animations": "~5.2.1",
    "@angular/common": "^5.2.1",
    "@angular/compiler": "^5.2.1",
    "@angular/core": "^5.2.1",
    "@angular/forms": "^5.2.1",
    "@angular/http": "^5.2.1",
    "@angular/platform-browser": "^5.2.1",
    "@angular/platform-browser-dynamic": "^5.2.1",
    "@angular/router": "^5.2.1",
    "@ngrx/effects": "^4.1.1",
    "@ngrx/router-store": "^4.1.1",
    "@ngrx/store": "^4.1.1",
    "@ngrx/store-devtools": "^4.1.1",
    "@ngx-progressbar/core": "^3.0.1",
    "@ngx-progressbar/http-client": "^3.0.1",
    "@ngx-translate/core": "^9.1.1",
    "@ngx-translate/http-loader": "^2.0.1",
    "arrive": "^2.3.1",
    "bootstrap": "4.0.0-alpha.6",
    "bootstrap-datepicker": "1.6.4",
    "bootstrap-social": "^5.1.1",
    "core-js": "^2.5.2",
    "font-awesome": "4.7.0",
    "fs": "0.0.1-security",
    "hammerjs": "^2.0.8",
    "i": "^0.3.6",
    "lodash": "^4.17.4",
    "materialize-css": "0.100.2",
    "nativescript-angular": "~5.2.0",
    "nativescript-background-http": "^3.2.7",
    "nativescript-bottom-navigation": "^1.1.2",
    "nativescript-bottombar": "^3.0.8",
    "nativescript-cardview": "^2.0.5",
    "nativescript-checkbox": "^3.0.3",
    "nativescript-floatingactionbutton": "^4.1.3",
    "nativescript-fresco": "^3.0.2",
    "nativescript-imagepicker": "^5.0.0",
    "nativescript-localstorage": "^1.1.5",
    "nativescript-mediafilepicker": "^1.0.5",
    "nativescript-modal-datetimepicker": "^1.1.0",
    "nativescript-ng-shadow": "^2.1.0",
    "nativescript-oauth": "^2.1.2",
    "nativescript-phone": "^1.3.1",
    "nativescript-photoviewer": "^1.4.0",
    "nativescript-snackbar": "^2.0.0",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-ui-listview": "^3.5.7",
    "nativescript-ui-sidedrawer": "^4.1.1",
    "ng2-validation": "^4.2.0",
    "ngrx-store-freeze": "^0.1.9",
    "ngx-pagination": "^3.0.3",
    "node-sass": "^4.9.0",
    "npm": "^4.2.0",
    "osenv": "^0.1.4",
    "path": "^0.12.7",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^5.5.5",
    "tether": "^1.4.3",
    "tns-core-modules": "^4.1.0",
    "url": "^0.11.0",
    "velocity-animate": "^1.5.1",
    "zone.js": "0.8.5"
    },
    "devDependencies": {
    "@angular-devkit/core": "~0.6.3",
    "@angular/compiler-cli": "^5.2.1",
    "@ngtools/webpack": "~6.0.8",
    "@types/googlemaps": "^3.30.8",
    "@types/jasmine": "^2.8.5",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "clean-webpack-plugin": "~0.1.19",
    "copy-webpack-plugin": "~4.5.1",
    "css-loader": "~0.28.11",
    "del": "^2.2.2",
    "extract-text-webpack-plugin": "~3.0.2",
    "fs-walk": "0.0.2",
    "gulp": "^4.0.0",
    "gulp-debug": "^3.1.0",
    "gulp-exec": "^3.0.1",
    "gulp-if": "^2.0.2",
    "gulp-rename": "^1.2.2",
    "gulp-spawn": "^0.4.0",
    "gulp-string-replace": "^0.4.0",
    "lazy": "1.0.11",
    "mkdirp": "^0.5.1",
    "nativescript-css-loader": "~0.26.1",
    "nativescript-dev-android-snapshot": "^0.0.11",
    "nativescript-dev-sass": "^1.6.0",
    "nativescript-dev-typescript": "~0.7.0",
    "nativescript-dev-webpack": "^0.12.0",
    "nativescript-worker-loader": "~0.9.0",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.3.0",
    "run-sequence": "^2.2.1",
    "sass-loader": "~6.0.6",
    "tns-platform-declarations": "^4.1.0",
    "typescript": "~2.7.2",
    "typescript-register": "^1.1.0",
    "uglifyjs-webpack-plugin": "~1.2.5",
    "webpack": "~4.6.0",
    "webpack-bundle-analyzer": "^2.13.1",
    "webpack-sources": "~1.1.0",
    "webpack-cli": "~2.1.3"
    },

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

1- Create a new ns project
2- Create a custom MainActivity
3- build the app with : tns build android --env.profile=mprod --bundle --env.aot --env.uglify --env.snapshot

Copied from original issue: NativeScript/NativeScript#5928

@tsonevn
Copy link
Author

tsonevn commented Jun 8, 2018

From @RadouaneRoufid on June 7, 2018 21:26

I also tried to add the activity in the appComponents of webpack.config.js

    const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/MainActivity.ts"),
    ];

but same problem.

@NickIliev
Copy link
Contributor

There are some changes in nativescript-dev-webpack as described in this migration blog post.

Apart from setting the MainActivity key, the custom activity should be added to `appComponents in webpack.config.js
For example:

    const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/MainActivity.android.ts")
    ];

Where the extended activity file is in app folder

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 8, 2018

As I mentionned, I also tried the following:

const appComponents = [
    "tns-core-modules/ui/frame",
    "tns-core-modules/ui/frame/activity",
    resolve(__dirname, "app/MainActivity.android.ts")
];

and I even tested with multiple variant
resolve(__dirname, "app/MainActivity.android.ts")
resolve(__dirname, "app/MainActivity.android")
resolve(__dirname, "app/MainActivity")
resolve("app/MainActivity.android.ts")

but still get the error.

@NickIliev NickIliev reopened this Jun 8, 2018
@NickIliev
Copy link
Contributor

@RadouaneRoufid I've just noticed that you have tried this approach. I will create a test application and post it here with the results.

@RadouaneRoufid
Copy link

Thank you NickIliev. I updated my previous comment by adding the different approach I tested.

@NickIliev
Copy link
Contributor

NickIliev commented Jun 8, 2018

@RadouaneRoufid I've used this project for testing purposes, and the webpack bundle was successful at my side.

The changes in webpack.config. file is here and here.
This is the extended activity used in the application and here the activity is added in AndoridManifest.xml.

Let me know if the project is building on your side - you can also use it as a reference.
NOte: You might want to update your Angular related dependencies

@RadouaneRoufid
Copy link

I cloned your project, and I have the same error

Built at: 2018-06-08 12:16:15
 2 assets
  [2] ../node_modules/@angular/router/fesm5/router.js + 14 modules 338 KiB {0} [built]
      |    15 modules
  [4] ../node_modules/rxjs/_esm5/internal/Observable.js + 1 modules 13.2 KiB {0} [built]
      |    2 modules
  [6] ../node_modules/rxjs/_esm5/internal/observable/of.js + 1 modules 1.17 KiB {0} [built]
      |    2 modules
 [12] ../node_modules/rxjs/_esm5/internal/Subscription.js + 2 modules 8.64 KiB {0} [built]
      |    3 modules
 [13] ../node_modules/rxjs/_esm5/internal/observable/from.js + 5 modules 6.33 KiB {0} [built]
      |    6 modules
 [50] ../node_modules/rxjs/_esm5/internal/util/subscribeToResult.js + 1 modules 1.56 KiB {0} [built]
      |    2 modules
[130] ../$$_lazy_route_resource lazy namespace object 160 bytes {1} [built]
[159] ./package.json 135 bytes {1} [optional] [built]
[166] ./app.module.ngfactory.js + 9 modules 17.7 KiB {1} [built]
      | ./app.module.ngfactory.js 6.71 KiB [built]
      | ./app.module.ts 426 bytes [built]
      | ./app.component.ts 140 bytes [built]
      | ./item/item.service.ts 1.43 KiB [built]
      | ./item/items.component.ts 660 bytes [built]
      | ./item/items.component.ngfactory.js 3.15 KiB [built]
      | ./item/item-detail.component.ts 558 bytes [built]
      | ./item/item-detail.component.ngfactory.js 2.46 KiB [built]
      | ./app.component.ngfactory.js 1.65 KiB [built]
      | ./app.routing.ts 466 bytes [built]
[181] ../node_modules/rxjs/_esm5/index.js + 44 modules 154 KiB {0} [built]
      |    45 modules
[212] ./app.css 746 bytes {1} [optional] [built]
[213] . sync nonrecursive ^\.\/app\.(css|scss|less|sass)$ 174 bytes {1} [built]
[215] ./MainActivity.android.js 2.56 KiB {0} [built]
[247] ./main.aot.ts 791 bytes {1} [built]
[248] ../node_modules/rxjs/_esm5/internal/operators/share.js + 1 modules 3.59 KiB {0} [built]
      |    2 modules
    + 318 hidden modules

ERROR in Entry module not found: Error: Can't resolve 'MainActivity' in '/home/me/mainact/NS-Issues-2018-II/nativescript-dev-webpack/extendActivity/app'

I'm using tns--version 4.1.0 and node 8.11.2. is it same as you ?

@RadouaneRoufid
Copy link

I'm still struggling with this with no solution !! Any idea to make it work ? or workaround it ?

@jibon57
Copy link

jibon57 commented Jun 10, 2018

Oh! I was about to open another issue. I am facing same problem & I have written it here too:

#65 (comment)
#65 (comment)

@tsonevn @NickIliev Please try to extend both Application & Activity in fresh project. It will always give error.

@RoyiNamir
Copy link

@RadouaneRoufid Can you try resolve(__dirname, "app/MainActivity") instead ?
We also ( in 4.0 , not 4.1) used

 entry: {
            bundle: aot ? "./main.aot.ts" : "./main.ts",
            vendor: "./vendor",
            MainActivity: "./appcompat-activity",
            MainIosActivity: "./delegate",
            DocumentPacker: "./core/models/core/documentPickerDelegate.model"
        },

as you notice , no ts , no android

@RadouaneRoufid
Copy link

@RoyiNamir I already tried your solution. The MainActivity is correctly recognized and picked up. I verified that in the console output and by generating a report.

with a -- bundle option, the build succeed without console errors. But when starting the app on device or emulator, the classNotFoundExcetion occurs. I tried to understand why it does not work and I realized the java class of the @JavaProxy is not generated as you can see below

image

while without --bundle option, a MainActivity.java exists under org.bricool as below :

image

So my mission now is to understand why and locate the code responsible for that generation.

@NickIliev I really appreciate if you can tell us what plugin or code is reponsible for generating the java class ?

@RoyiNamir
Copy link

@RadouaneRoufid do you use uglify when bundle?

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 10, 2018

Yes.

The commad I execute
tns run android --env.profile=emulator --env.aot --env.uglify --env.snapshot --bundle --device avd27

@RoyiNamir
Copy link

RoyiNamir commented Jun 10, 2018

Can u plz try without. Iirc, we also had it and it was related. Also remove snapshot for now. Nick told me before something about it. Wait ill search ...

Edit : found it : see what @NickIliev told me about snapshot. ( also , custom activity POV)
#446 (comment)

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 10, 2018

You are right. It generates the Java class but I have now an error :

Please change the name of one of the extended classes.
File:/home/ruser/projects/nativescript/platforms/android/app/src/main/java/org/bricool/MainActivity.java Class: org.bricool.MainActivity
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:78)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:48)

@RoyiNamir
Copy link

RoyiNamir commented Jun 10, 2018

@RadouaneRoufid ^ try last comment :) (snapshot thingy in nick comment to me)

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 10, 2018

I tried with vendor-platform.android.ts. It does not work.

Note that this file should be removed according to latest migration guide.

@RadouaneRoufid
Copy link

Sorry, I forgotted an important word in my last comment :).

It does NOT work. the .java file is not generated.

@RoyiNamir
Copy link

RoyiNamir commented Jun 11, 2018

We updated the project today. - getting the same error

ERROR in Entry module not found: Error: Can't resolve 'MainActivity' in 'C:\projects-web-storm\digital\dsapp1\app'

using in webpack :

  const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/MainActivity.android.js")                <-------------
    ];

And :

  entry: {
            bundle: entryPath,
            MainActivity: "MainActivity"
        },

image

declared here :

image

tsconfig
package.json

full error :
image

@RadouaneRoufid Did you find a solution?
@NickIliev we're also facing this issue. If you can't re-make this issue , I have no problem sending the proj via file ( privately).

@RadouaneRoufid
Copy link

Replace

entry: {
           bundle: entryPath,
           MainActivity: "MainActivity"
       },

by

entry: {
          bundle: entryPath,
          MainActivity: "./MainActivity"
      },

Do you have an import of MainActivity in you main.aot.ts ?

@RoyiNamir
Copy link

RoyiNamir commented Jun 11, 2018

@RadouaneRoufid I was looking at Nick's code - hence I was doing it without ./.

Will try now and update.

Regarding the other question :

main.aot.ts

// this import should be first in order to load some required settings (like globals and reflect-metadata)
 
import { platformNativeScript } from "nativescript-angular/platform-static";

// "./app.module.ngfactory" is a dynamically generated module when compiled with AoT.
import { AppModuleNgFactory } from "./app.module.ngfactory";

platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory);

Worth to mention

After each change I do :

tns prepare android && tns run android --bundle --env.uglify --env.aot

The update : Now I get only this error :

https://i.imgur.com/9P5jLor.jpg

@RoyiNamir
Copy link

@RadouaneRoufid How do you import the activity in the AOT file ?

@RadouaneRoufid
Copy link

You don't have to import your activity in main.aot.ts. Your error complains about it in main.aot.ts but I do not see any import of it.

Try tns platform remove android && tns add remove android and rebuild.

@RoyiNamir
Copy link

RoyiNamir commented Jun 11, 2018

@RadouaneRoufid Did that - Same error : see that it doesn't have slashes :

ERROR in ./main.aot.ts
Module not found: Error: Can't resolve 'C:projects-web-stormdigitaldsapp1appMainActivity.android.js' in 'C:\projects-web-storm\digital\dsapp1\app'
 @ ./main.aot.ts 5:0-75

image

this is NOt the folder. The folder is :

c:\projects-web-storm\digital\dsapp1\app\

@RadouaneRoufid
Copy link

Can you output the result of resolve(__dirname, "app/MainActivity.android.js") ?

console.log(resolve(__dirname, "app/MainActivity.android.js"));

@RoyiNamir
Copy link

@RadouaneRoufid
image

C:\projects-web-storm\digital\dsapp1\app\MainActivity.android.js

@RadouaneRoufid
Copy link

I have seen a let OnRouteToURL: ReplaySubject<string>; in your previous code, and I think that we are using the same code to navigate to the correct route on app start.

Do you have a require('./MainActivity.android'); in your app.components.ts ?

@RoyiNamir
Copy link

RoyiNamir commented Jun 11, 2018

@RadouaneRoufid It ^ happens also in a plain test project. reported here. It's weird that you don't get this error. Can you delete all the app folder ( keeping only config and init files) and send only just the config files ( including hooks) project so I will make a comparison ? I can send you a picture which differences. ( beyond compare tool)

@RadouaneRoufid
Copy link

What I suggest you is to do this :
1- Delete those dirs : rm -rf node_modules hooks platforms
2- Delete gradle : rm -rf ~/.gradle (to get gradle 4.x)
3- Clear npm cache : npm cache clear -f
4- Install globally node 8.11.x
5- Install your project : npm install
6- ./node_modules/.bin/update-ns-webpack --configs
7- tns platform add android
8- tns build android --bundle --env.aot --env.uglify --env.snapshot

And tell me what you got.

@RoyiNamir
Copy link

RoyiNamir commented Jun 12, 2018

@RadouaneRoufid Will sure Do. ( when I'm at work). I wonder if @NickIliev 's code compiles (and runs!) with all those flags without error....
Can you plz run Nick's project with aot uglify bundle and see if there's error ?

@vchimev
Copy link
Contributor

vchimev commented Jun 13, 2018

Hey @RadouaneRoufid, @RoyiNamir, @jibon57,

could you please remove MainActivity from config's entry and leave only the bundle key as follows:

NickIliev/NS-Issues-2018-II@ef107e1?diff=unified

@RoyiNamir
Copy link

RoyiNamir commented Jun 13, 2018

@vchimev So stuff like this :

//old version
  entry: {
            bundle: aot ? "./main.aot.ts" : "./main.ts",
            vendor: "./vendor",
            MainActivity: "./appcompat-activity",        <------
            MainIosActivity: "./delegate",                     <------
            DocumentPacker: "./core/models/core/documentPickerDelegate.model" <------
        },

should be ONLY in appComponents section ?

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 13, 2018

const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/MainActivity.android.ts")
    ];

entry: {
            bundle: entryPath
        },

Problem still there after removing MainActivity from config's entry
image

Java file is not being generated

@vchimev
Copy link
Contributor

vchimev commented Jun 13, 2018

Hey there,

I created this android-extend-ng sample app where I extended Android activity. Also, I added the app/activity.android.ts to appComponents in the webpack.config.js and was able to successfully execute the application with all the commands:

tns run android
tns run android --bundle
tns run android --bundle --env.aot --env.uglify --env.snapshot --release --keyStorePath <keyStorePath> --keyStorePassword <keyStorePassword> --keyStoreAlias <keyStoreAlias> --keyStoreAliasPassword <keyStoreAliasPassword>

Could you please give it a try at your end? If successful, could you please try to git clean -fdx your projects and execute the application with such a configuration?

Thanks,
@vchimev

@RoyiNamir
Copy link

RoyiNamir commented Jun 13, 2018

@vchimev Hi. In Windows - Still No.

I'veDownloaded your project :

image

(npm isntall X2 , tns platform add android)

Running first tns run android --bundle --env.aot --env.uglify

You can see the screen video here :
https://i.imgur.com/VJ1M02s.gif

final result :

image

image

If you want to test on my win machine ( ...just say)

@RadouaneRoufid
Copy link

I confirm that your project works on a Linux platform. I'm trying to figure out why it does not with mine.

@jibon57
Copy link

jibon57 commented Jun 13, 2018

That's a known bug. If you have a Linux or Mac then can try. Windows has problem. I haven't tried the solution. Will try in morning

@RoyiNamir
Copy link

^windows 10 , nope

@jibon57
Copy link

jibon57 commented Jun 13, 2018

@RadouaneRoufid , I think new Android directory structure created that conflict with old. Is your project using old Android directory structure? app/App_Resources/android

@RoyiNamir
Copy link

@jibon57 I've created a plain new project in a new directory and it still fails. See my response ^. Windows doesn't have a problem . It is with the plugin.

Let's wait for an answer from @vchimev

@RadouaneRoufid
Copy link

You are totally right. there is a huge difference between my App_resources and the android-extend-ng one

@jibon57
Copy link

jibon57 commented Jun 13, 2018

@RoyiNamir please check here:

#544

@RoyiNamir
Copy link

RoyiNamir commented Jun 13, 2018

@jibon57 So ? it's not a problem with windows. it's a problem with how it was written to handle directories in windows.
Let's wait for an answer.

@vchimev
Copy link
Contributor

vchimev commented Jun 13, 2018

Thanks, Guys!

Today we released [email protected] which contains a fix for paths format on Windows. Could you please update to it and try again?

I would be able to look into this tomorrow morning.

@RoyiNamir
Copy link

RoyiNamir commented Jun 13, 2018

@vchimev

Still no....

  • npm prune
  • npm cache clear -f
  • tns platform remove android
  • tns platform add android
  • npm install [email protected] -f -D ( within your project androidextendng)
  • npm install X2
  • tns run android --bundle --env.aot --env.uglify

Video Result : https://i.imgur.com/eoQ4m50.gif

image

webpackconfig file ( from your project)

update

@vchimev I took one more shot :

  • completely deleting all folders ,
  • downloaded your zip file again ,
    -npm isntall , platform add...
  • running the ns-webpack update command --configs
    -npm install again
  • tns run android --bundle --env.aot --env.uglify

Then I got many errors :

image

Full report : https://pastebin.com/raw/uEguqJ3y

@jibon57
Copy link

jibon57 commented Jun 14, 2018

@vchimev I have tried but not working from my side too. I did like this:

npm install --save  [email protected]
./node_modules/.bin/update-ns-webpack --deps
./node_modules/.bin/update-ns-webpack --configs

Then in webpack.config.js

const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
	resolve(__dirname, "app/MainApplication.android.ts")
];

But I got this error:

ERROR in ./main.ts
Module not found: Error: Can't resolve 'D:OthersDocumentsoneDriveMy_Worksmob_appsmynarsaappMainApplication.android.ts' in 'D:\Others\Documents\oneDrive\My_Works\mob_apps\mynarsa\app'
 @ ./main.ts 5:0-96

Then I have changed like this:

const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
	"../app/MainApplication.android.ts"
];

This time compile was successful like this:

[./ sync ^\.\/app\.(css|scss|less|sass)$] . sync nonrecursive ^\.\/app\.(css|scss|less|sass)$ 160 bytes {bundle} [built]
[./MainApplication.android.ts] 1.41 KiB {bundle} [built]
[./app-routing.module.ts] 798 bytes {bundle} [built]

But when the app was open that time it got crashed:

ActivityManager: Start proc 1816:com.myna.mynarsa/u0a289 for activity com.myna.mynarsa/com.tns.NativeScriptActivity
System.err: com.tns.NativeScriptException: Failed to create JavaScript extend wrapper for class 'com/myna/Application'
System.err:     at com.tns.Runtime.createJSInstanceNative(Native Method)
System.err:     at com.tns.Runtime.createJSInstance(Runtime.java:643)
System.err:     at com.tns.Runtime.initInstance(Runtime.java:618)
System.err:     at com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:234)
System.err:     at com.myna.Application.onCreate(Application.java:21)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
System.err:     at android.app.ActivityThread.-wrap2(ActivityThread.java)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:154)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
System.err: java.lang.RuntimeException: Unable to create application com.myna.Application: com.tns.NativeScriptException: JavaScript object for Java ID 0 not found.
System.err: Attempting to call method onCreate
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
System.err:     at android.app.ActivityThread.-wrap2(ActivityThread.java)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:154)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
System.err: Caused by: com.tns.NativeScriptException: JavaScript object for Java ID 0 not found.
System.err: Attempting to call method onCreate
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:970)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:954)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err:     at com.myna.Application.onCreate(Application.java:27)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
System.err:     ... 8 more
ActivityManager: Process com.myna.mynarsa (pid 1816) has died

@vchimev
Copy link
Contributor

vchimev commented Jun 14, 2018

@RoyiNamir,
I updated the appComponents path to activity in order to get the module found also on Windows.

@jibon57,
yes, extending Activity works fine, but there is a problem when extending Application which I'm going to look into next.

@jibon57
Copy link

jibon57 commented Jun 15, 2018

Thanks @vchimev . Any work around so far? I can't use --env.snapshot too :(

@RadouaneRoufid
Copy link

RadouaneRoufid commented Jun 15, 2018

I have this error when trying to bundle with --env.snapshot


Warning: there already is an extend called org.myApp.MainActivity.
Warning: The static binding generator will generate extend from:vendor.js implementation
Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:/home/ruser/IdeaProjects/deepan/deepan-parent/deepan-front/src/gui/nativescript/platforms/android/app/src/main/java/org/myApp/MainActivity.java Class: org.myApp.MainActivity
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:78)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:48)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:runSbg'.
> Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1

Any solution to this ? #568

@vchimev
Copy link
Contributor

vchimev commented Jun 19, 2018

Hey Guys,

I'm closing this issue as extending Activity works fine.

The problem with extending Application is going to be addressed and commented here. CC: @jibon57

@vchimev vchimev closed this as completed Jun 19, 2018
@vchimev vchimev removed their assignment Jun 19, 2018
@vchimev
Copy link
Contributor

vchimev commented Jun 23, 2018

Hey Guys,

Let me just follow up that adding a custom android app component to the array on the top of the webpack.config.js file should be resolved to an absolute path, i.e.
resolve(__dirname, "app/activity.android.ts") in order to be included in the common vendor.js chunk. Adding it by a relative path is only a workaround for this issue on Windows, which fix is on a pull request.

@RoyiNamir
Copy link

RoyiNamir commented Jun 23, 2018

@vchimev , just for full closure summarize : all the problems:

  • Missing slash in windows
  • extending activity with aot
  • extending app

And the right way is to use abosolute path like :

resolve(__dirname, "app/activity.android.ts")

Will be in resolved in 0.14.2?

Or does some are resolved in 0.14 already ?

@vchimev
Copy link
Contributor

vchimev commented Jun 23, 2018

Hey @RoyiNamir,

the issue that absolute paths in appComponents aren't resolved properly on Windows will be addressed in 0.14.2.

However, absolute paths work fine on macOS/Linux and also extending activity and application should work fine with the configurations described in this comment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants