Android Studio Android mobile phone simulator environment construction

1. Start the command prompt tool as an administrator

2. Clean up the old environment 

# 卸载Angular
npm uninstall -g @angular/cli
npm uninstall @angular/cli
npm uninstall -g angular
npm uninstall angular

# 卸载Ionic
npm uninstall -g @ionic/cli
npm uninstall  @ionic/cli
npm uninstall -g ionic
npm uninstall ionic

# 卸载Cordova
npm uninstall -g cordova
npm uninstall cordova

# 卸载native-run
npm uninstall -g native-run

# 清理缓存
npm cache clean --force

2. Unzip the JDK 11 provided in the folder (must be 11, not other versions. If JDK8 has been installed before, you need to uninstall JDK8 in the control panel first, delete the environment variable JAVA_HOME, and delete the environment variable involved in Path to the contents of JDK8; install JDK11 after restarting)

  

 Unzip the JDK to the C:\dev directory, so the path structure is C:\dev\jdk-11.0.17

3. Register environment variables (when starting the command line, use "Run as administrator" in the right-click menu)

# 注册JAVA_HOME环境变量
setx JAVA_HOME "C:\dev\jdk-11.0.17"

# 将JDK命令注册到path环境变量(用户级)
setx Path "%Path%;C:\dev\jdk-11.0.17\bin"

If the system has originally been configured with the JAVA_HOME environment variable, or there is already JDK or Open JDK in the Path environment variable, you should delete it first (see Baidu for the method), and then execute the above command.

4. Install the latest version of Android Studio. After the installation is complete, create a new project in Android Studio.

5. Install Android SDK 12 in Android Studio (other installed Android SDK versions need to be deleted in advance, remove the small √ in front of the corresponding version to delete)

6. Create a virtual device in Android Studio (you may need to turn on VPN)

 

7. Start the virtual machine in the virtual device list 

 

8. Install Android SDK Tools and SDK Command-line Tools (latest)

Android Studio → Tools → SDK Manager → SDK Tools → Uncheck "Hide Obsolete Packages" → Select "Android SDK Tools (Obsolete)"

9. Register in environment variables 

# 注册环境变量ANDROID_SDK_ROOT
setx ANDROID_SDK_ROOT "%LOCALAPPDATA%\Android\Sdk"

# 注册组件:cmdline-tools/latest/bin    emulator    platform-tools    build-tools
setx Path "%PATH%;%LOCALAPPDATA%\Android\Sdk\cmdline-tools\latest\bin;%LOCALAPPDATA%\Android\Sdk\emulator;%LOCALAPPDATA%\Android\Sdk\platform-tools;%LOCALAPPDATA%\Android\Sdk\build-tools"

 10. Install Angular

npm install -g @angular/cli  # 安装Angular最新版本
npm list -global --depth 0    # 查看安装的Angular版本

 11. Install Ionic version 6

npm install -g @ionic/[email protected]
ionic --version    # 查看Ionic版本

12. Install Cordova version 11

npm install -g [email protected]

13. Unzip Gradle and register the Gradle command to the Path environment variable

I unzipped Gradle to the C:\dev directory, so the path structure is C:\dev\gradle-8.0.2

setx Path "%Path%;C:\dev\gradle-8.0.2\bin"
gradle -v  # 验证是否安装成功
# 如果成功了则关闭该命令行窗口,重新以管理员身份开一个命令行窗口

14. Create an Ionic application and test whether it is initially successful (my D:/codes/js directory is the root directory of the project)

D:
cd codes/js
ionic start ionic-demo tabs
ionic serve --open  # 测试是否成功,如果可以看到网页,则在命令行中按Ctrl+C多次来终止程序

# 进入到新项目的目录
cd ionic-demo
# 为项目添加安卓平台环境
ionic cordova platform add android
# 提示:Are you sure you want to continue?   回答Y
# 过程中可见到安装了[email protected]

# 安装native-run
npm install -g native-run

# 安装@ionic/cordova-builders
ng add @ionic/cordova-builders

ionic cordova emulate android --verbose
# 此时可能提示Build Success,但遇到了错误,cannot find output file
# 忽略错误,跑到输出目录,将APK文件丢进虚拟机,就可以运行了
# 输出目录:D:\codes\js\ionic-demo\platforms\android\app\build\outputs\apk\debug

14. Prepare to create a Cordova project

Python 3.9.13 and node 18.15.0 are installed on my machine. I need to find the saas version corresponding to node.

NodeJS

Supported node-sass version

Node Module

Node 19

8.0+

111

Node 18

8.0+

108

Node 17

7.0+, <8.0

102

Node 16

6.0+

93

Node 15

5.0+, <7.0

88

Node 14

4.14+

83

Node 13

4.13+, <5.0

79

Node 12

4.12+, <8.0

72

Node 11

4.10+, <5.0

67

Node 10

4.9+, <6.0

64

Node 8

4.5.3+, <5.0

57

Node <8

<5.0

<57

(Table source: https://www.npmjs.com/package/node-sass)

# 安装node-sass 8.0.0
npm install --msvs_version 2015
npm install -g mirror-config-china --registry=https://registry.npmmirror.com
npm install node-sass

# 创建Cordova项目
ionic start ionic2 sidemenu --type=angular
# Integrate your new app with Capacitor to target native iOS and Android?   No

ionic cordova platform add android

npm install @awesome-cordova-plugins/core

# 添加cordova插件,作业中替换成自己所需的插件
# SCU网站上用的都是@ionic-native/xxx,现在都改成@awesome-cordova-plugins/xxx
npm install @awesome-cordova-plugins/network   # 用于替换@ionic-native/network
ionic cordova plugin add cordova-plugin-network-information

npm install @awesome-cordova-plugins/camera    # 用于替换@ionic-native/camera
ionic cordova plugin add cordova-plugin-camera

ng add @ionic/cordova-builders

# 编译生成APK
ionic cordova emulate android

# 将输出路径上的APK丢进虚拟机
# 输出路径:D:\codes\js\ionic2\platforms\android\app\build\outputs\apk\debug\app-debug.apk

other:

ionic cordova platform add android           添加android平台
不一定用  npm i -g native-run  
ionic cordova emulate android -l  可以在运行时自动更新
ionic cordova run android         不能自动更新的
ionic cordova emulate browser   在浏览器运行
ionic integrations disable capacitor capacitor报错用和scu module5最下面那个错一样
npm install -g cordova   安装cordova
--force
npm install @awesome-cordova-plugins/core 安装插件的格式
ionic cordova build android 构建apk文件
npm i @awesome-cordova-plugins/core 添加完新插件用 要不会报错

Memo:

Android 10: API version 29

Android 11: API version 30

Android 12: API version 31

Android 13: API version 32

cordova-android Version

Supported Android API-Levels

Equivalent Android Version

11.X.X

22 - 32

5.1 - 12.0.0 (L)

10.X.X

22 - 30

5.1 - 11.0.0

9.X.X

22 - 29

5.1 - 10.0.0

8.X.X

19 - 28

4.4 - 9.0.0

7.X.X

19 - 27

4.4 - 8.1

6.X.X

16 - 26

4.1 - 8.0.0

5.X.X

14 - 23

4.0 - 6.0.1

4.1.X

14 - 22

4.0 - 5.1

4.0.X

10 - 22

2.3.3 - 5.1

3.7.X

10 - 21

2.3.3 - 5.0.2

Check the version of the Cordova-Android package:

Cordova platform ls  # 在项目文件夹中执行

Android SDK Tools

In Android Studio 3.6 and higher, independent Android SDK Tools need to be installed

Android Studio → Tools → SDK Manager → SDK Tools → Uncheck "Hide Obsolete Packages" → Select "Android SDK Tools (Obsolete)"

Environment variables:

① JAVA_HOME:

② ANDROID_SDK_ROOT:

③ PATH: (both in ANDROID SDK ROOT)

cmdline-tools/latest/bin

emulator

platform-tools

build-tools (requires apksigner and zipalign to be installed)

Set npm to download software from domestic mirrors

npm config set registry https://registry.npm.taobao.org

Guess you like

Origin blog.csdn.net/qq_54813250/article/details/130314935