第2世界
发布于 2023-05-22 / 33 阅读 / 0 评论 / 0 点赞

react native使用expo框架

项目初始化

使用expo的“bare React Native app with Expo tools”,是因为我使用expo直接创建的项目在通过本地构建的时候报错。

npx create-expo-app --template bare-minimum

直接使用create-expo-app项目在运行npx expo run:android --variant release的时候编译报错:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

-----------

* Where:

Build file '/Users/liukun/Desktop/app1234/android/app/build.gradle' line: 2

* What went wrong:

A problem occurred evaluating project ':app'.

> Could not find implementation class 'com.facebook.react.ReactPlugin' for plugin 'com.facebook.react' specified in jar:file:/Users/liukun/.gradle/caches/jars-9/f47c830d8d52f951a5914d78738d6b24/react-native-gradle-plugin.jar!/META-INF/gradle-plugins/com.facebook.react.properties.

* Try:

> Run with --stacktrace option to get the stack trace.

> Run with --info or --debug option to get more log output.

> Run with --scan to get full insights.

==============================================================================

2: Task failed with an exception.

-----------

* What went wrong:

A problem occurred configuring project ':app'.

> compileSdkVersion is not specified. Please add it to build.gradle

* Try:

> Run with --stacktrace option to get the stack trace.

> Run with --info or --debug option to get more log output.

> Run with --scan to get full insights.

==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

5 actionable tasks: 5 up-to-date

Error: /Users/liukun/Desktop/app1234/android/gradlew exited with non-zero code: 1

Error: /Users/liukun/Desktop/app1234/android/gradlew exited with non-zero code: 1

  at ChildProcess.completionListener (/Users/liukun/Desktop/app1234/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)

  at Object.onceWrapper (node:events:628:26)

  at ChildProcess.emit (node:events:513:28)

  at maybeClose (node:internal/child_process:1091:16)

  at ChildProcess._handle.onexit (node:internal/child_process:302:5)

  ...

  at Object.spawnAsync [as default] (/Users/liukun/Desktop/app1234/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)

  at spawnGradleAsync (/Users/liukun/Desktop/app1234/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)

  at Object.assembleAsync (/Users/liukun/Desktop/app1234/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)

  at runAndroidAsync (/Users/liukun/Desktop/app1234/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:31:24)

解决办法是修改android/gradle/wrapper/gradle-wrapper.properties中的版本将gradle从默认的7.5.1改为7.6.1

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip

目前仅针对当前默认生成的版本:expo 48.0.15, react-native 0.71.7。后期如果出现问题也可以尝试从这方面考虑。

splash screen

npx expo-splash-screen -i assets/mysplash.png -b #ffffff

查看使用帮助

npx expo-splash-screen --help

运行

npm run android


评论