96
loading...
This website collects cookies to deliver better user experience
getServerSideProps
. Sadly, they won't work with capacitor. Next.js wasn't really meant to be used for mobile development.yarn
here but you can use npm
as well.java -version
yarn create next-app next-capacitor-app
yarn add @capacitor/core @capacitor/cli @capacitor/android @capacitor/ios
npx cap init next-capacitor-app com.nextcap.app --web-dir=out
# The format as per capacitor docs
# npx cap init [name] [id] --web-dir=build
web-dir
as out
because when we export assets it'll be there in the out
directory.npx cap add android
npx cap add ios
pages/index.js
and edit it to get a basic page.import React from 'react'
export default function Home() {
return (
<div>
<h1>
Hey there!
</h1>
</div>
)
}
yarn run build && npx next export
next export
command to your scripts
section in your package.json
.npx cap sync
adb
first.adb devices
# if a device appears, run the next command.
# else accept a pop up if it appears on your device
npx cap run
npx cap init [***]
, a capacitor.config.json
file will be created in the root of your project. Let's go ahead and edit it so that we can add a server for live reload!ifconfig
ifconfig
works fine. If you're on windows, you can try running ipconfig
.192.168.1.9
. So I'll be using that.capacitor.config.json
, add this:{
"server": {
"url": "http://192.168.1.9:3000"
}
}
yarn run build
npx next export
npx cap sync
yarn dev
npx cap run
capacitor.config.json
before building your release APK.yarn add @capacitor-community/electron
npx cap add electron
npx cap sync
npx cap open electron