NativeScript / nativescript-dev-webpack

A package to help with webpacking NativeScript apps.
Apache License 2.0
97 stars 49 forks source link

Uglify option prevents the generation of java class #1039

Closed fpaaske closed 4 years ago

fpaaske commented 5 years ago

Environment tns info

✔ Component nativescript has 6.1.0 version and is up to date. ✔ Component tns-core-modules has 6.1.0 version and is up to date. ✔ Component tns-android has 6.1.0 version and is up to date. ✔ Component tns-ios has 6.1.0 version and is up to date.

node -v v12.8.0

Relvant section of webpack.config.js

    // 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, "src/app/call-state-listener.ts"),
    ];

call-state-listener.ts:

@JavaProxy('com.company.BroadcastReceiver.CallStateListener')
export class CallStateListener extends android.content.BroadcastReceiver {

  constructor() {
    super();
    global.__native(this); // necessary in TS constructors if extending native class
  }

  public onReceive(context: android.content.Context, intent: android.content.Intent) {
  }
}

AndroidManifest.xml

        <receiver android:name="com.company.BroadcastReceiver.CallStateListener">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.PHONE_STATE_CHANGED" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

Describe the bug

When using the --env.uglify flag, the generated .class-file is missing from the apk-file. Without the flag, it works fine.

Might be related to #564

RadouaneRoufid commented 4 years ago

Any news on this ? I had opened https://github.com/NativeScript/nativescript-dev-webpack/issues/564 and still having the problem in tns 6.1.2

RadouaneRoufid commented 4 years ago

I found the solution. "noEmitHelpers": true, must be present in compilerOptions in tsconfig.json while build with env.uglify with custom activity.

Fatme commented 4 years ago

@RadouaneRoufid,

It is recommend to set noEmitHelpers: true regardless if you building with env.uglify or extending platform native classes. More info can be found here.

However, I'm glad to hear you resolved your issue so I'm closing this thread.