09 กรกฎาคม 2561

convert create-react-app to android/ios mobile application using cordova

steps

  • install jdk 1.8
  • install android studio
  • install gradle by running brew install gradle
  • accept android license by running ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
  • install cordova by running sudo npm install -g cordova
  • create cordova app by running cordova create mycordova
  • goto mycordova cd mycordova
  • create react application inside mycordova by running create-react-app myweb
  • modify myweb/public/index.html like this

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src * data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>



  • modify myweb/package.json like this
{
"name": "sample-app",
"version": "0.1.0",
"private": true,
"homepage": "./", // <- add="" span="">
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && cp -a ./build/. ../www/", // <- add="" span="">
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}

  • inside myweb run npm run build
  • goback to mycordova folder and then run cordova build to generate .apk file or run cordova run andriod to build and run app


ไม่มีความคิดเห็น:

แสดงความคิดเห็น

บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (1 ปีย้อนหลัง)