From b16e361cd3ab5f48059254b7ee20290e89724c2e Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 6 Jan 2026 23:25:07 -0800 Subject: [PATCH] feat: custom android activities with vite --- ...ses-and-implementing-interfaces-android.md | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/content/guide/extending-classes-and-implementing-interfaces-android.md b/content/guide/extending-classes-and-implementing-interfaces-android.md index 5d9f8626..0fb32eb2 100644 --- a/content/guide/extending-classes-and-implementing-interfaces-android.md +++ b/content/guide/extending-classes-and-implementing-interfaces-android.md @@ -487,9 +487,11 @@ Next, modify the activity in `App_Resources/Android/src/main/AndroidManifest.xml android:configChanges="keyboardHidden|orientation|screenSize"> ``` -To include the new Activity in the build, make sure it's added to the `webpack.config.js` with the following: +To include the new Activity in the build, make sure it's configured with the bundler you're using (webpack or vite): -```js +::: code-group + +```js [webpack] const webpack = require('@nativescript/webpack') module.exports = (env) => { @@ -502,6 +504,31 @@ module.exports = (env) => { } ``` +```ts [vite] +import { defineConfig } from 'vite'; +import { typescriptConfig, appComponentsPlugin } from '@nativescript/vite'; + +export default defineConfig(({ mode }) => { + const config = typescriptConfig({ mode }); + + // Register custom Android Activity and Application classes + config.plugins!.push( + appComponentsPlugin({ + appComponents: [ + // include any your app needs + './src/custom-activity.android.ts', + './src/custom-application.android.ts' + ], + platform: 'android' + }) + ); + + return config; +}); +``` + +::: + ## Implementing Kotlin and Java interfaces The next example shows how to implement an interface in Kotlin/Java with NativeScript. The main difference between inheriting classes and implementing interfaces in NativeScript is the use of the `extend` keyword. Implement an interface is done by passing the implementation object to the interface constructor function. The syntax is identical to [Java Anonymous Classes](https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html).