Closed RadouaneRoufid closed 6 years ago
There are few differences between your code VS the demo's code . Just saying .
Are you sure you use the .ts
version ?
For resolve(__dirname, "app/MainActivity.android.js"),
I tried with both .ts
and .js
. Got the error with the two.
I had to prefix MainActivity with ./
otherwise webpack didn't find the file.
For symlink, I tried to play with the option. I reverted it. It does not solve the problem.
@vchimev any work around so far regarding application extend?
Hey Guys,
Let me first refer to this pull request addressing the issue where an absolute path in appComponents
can't be resolved on Windows and pay attention 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 the issue above.
I updated all the demos to extend android activity and application in the same branch, and managed to execute them successfully with:
tns run android --bundle
tns run android --bundle --env.aot --env.uglify --env.snapshot --release ...
In regard to extend android activity, it should be added only to the appComponents
array by an absolute path as mentioned above.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
resolve(__dirname, "app/activity.android.ts"),
];
In this way and with the default config, these components get in the common vendor.js chunk and are required in the bundle by android-app-comopnents-loader
.
In regard to extend android application, it should be added only as an entry.
entry: {
bundle: entryPath,
application: "./application.android",
},
In this way, the source code of application.android.js|ts
is bundled separately as application.js
file which is loaded from the native Application.java
class on launch.
The application.js
bundle file is independent of the bundle.js
and vendor.js
files and the reason for it is that bundle.js
and vendor.js
are not loaded so early in the application launch.
That's why the logic in application.android.js|ts
is needed to be bundled separately in order to be loaded by the native Application.java
as early as needed on launch.
@vchimev @jibon57 @RadouaneRoufid Hello. Can you please explain why Vasil used in here :
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
resolve(__dirname, "app/activity.android.ts"),
];
1) .ts
in "app/activity.android.ts"
--------> isn't it suppose to be JS ? I mean it looks like as if the TS file will be included and not js included. ( I know that TS is transpiles to JS) - but still - why ts ?
2) .android
in "app/activity.android.ts"
--------> isn't it suppose to be without .android
? as it is removed.
Can you please shed some light about the steps that occur here ?
Hey @RoyiNamir,
.ts
files in TypeScript and Angular projects..android.|.ios.
are prepared for the specific platform on building without bundling. Then these platform specific files go to the specific native projects and the corresponding extension is removed. For bundling, they are handled through the loaders/plugins mentioned in 1.Hey @RadouaneRoufid and @jibon57,
I'm closing this as demos and docs were updated. Please, let me know in case of any other issues.
Hey @vchimev . Docs here you mean ?
found it . Thanks https://github.com/NativeScript/docs/commit/14224ddd1d894ab94d5b12a31431a063afdd4cb2#diff-bb3b3b05f6b7838c7b1041431d9b9f93
Any news on this ? Problem still present in tns 6.1.2
I found the solution. "noEmitHelpers": true
, must be present in compilerOptions
in tsconfig.json
while build with env.uglify
with custom activity.
Issue Checklist
Tell us about the problem
The issue 559 results in a problem in using --env.uglify option when using a custom application. In fact, the custom application Java Class is not generated causing an error on app start: ClassNotFoundException
with a
-- env.uglify
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 belowwhile without --env.uglify option, a MainActivity.java exists under org.bricool as below :
Local environment
Project data
[x] Node dependencies:
const { join, relative, resolve, sep } = require("path");
const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); const CleanWebpackPlugin = require("clean-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = env => { // Add your custom Activities, Services and other Android app components here. const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", resolve(__dirname, "app/MainActivity.android.ts") ];
};