Welcome! 🚀 This guide will walk you through converting your React Vite web app into a fully functional Android app using Capacitor and Android Studio. Whether you're a beginner or a pro, this guide has you covered! Let's turn your website into an app. 🎉
Live website Link : https://focuszen.netlify.app/
Before starting, make sure you have the following installed:
- Node.js and npm
- A React Vite project ready to go
- Android Studio installed on your laptop
- A connected Android device or emulator
Open your terminal in the project folder and run:
npm install @capacitor/core @capacitor/cli
This installs Capacitor's core and CLI tools.
Generate the production-ready files:
npm run build
This creates a dist
folder containing your web app files.
Add Capacitor to your project:
npx cap init
It will ask for:
- App Name: Give your app a name (e.g., "My App").
- App ID: Use a unique ID (e.g.,
com.example.myapp
).
Add Android as the platform:
npm install @capacitor/android
npx cap add android
You should now see an android
folder in your project directory.
Copy your dist
folder to the Android project:
npx cap copy
Launch Android Studio with this command:
npx cap open android
If you get an error like "Unable to launch Android Studio", make sure Android Studio is correctly installed and added to your PATH.
- In Android Studio, open the project from the
android
folder. - Go to Build > Build Bundle(s)/APK(s) > Build APK(s).
- Wait for the build to finish.
- Once the build completes, click the Locate button in the bottom-right popup.
- Transfer the generated
app-debug.apk
to your phone via USB or cloud storage. - Install the APK by opening it on your phone (you may need to enable "Install from unknown sources" in your phone settings).
- After installation, go to your phone's App Drawer (list of all apps).
- Search for your app by the name you provided in Step 3.
- Open it and enjoy your app on mobile! 🎉
Fix: Ensure Android Studio is installed and added to your PATH environment variable.
Fix: Ensure the AndroidManifest.xml
file has the correct intent filters:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Fix: Make sure you’ve copied the dist
folder correctly and run npx cap sync
after any changes.
Congratulations! 🎊 You’ve successfully converted your React Vite app into an Android app. This guide ensures you can build, install, and run your app without any hiccups.