初始化项目:
npx create-expo-app --template bare-minimum
安装依赖:
npm install
生成本地android项目:npx expo run:android
运行:
npm run android
打包debug版本:
npx expo run:android
打包apk:
npx expo run:android --variant release
打包aab:
npx react-native build-android --mode=release
遇到的问题:
1.找不到com.google.android:cameraview:1.0.0
Could not find com.google.android:cameraview:1.0.0
解决办法:
在android/build.gradle文件中allprojects/repositories添加
maven {
// expo-camera bundles a custom com.google.android:cameraview
url "$rootDir/../node_modules/expo-camera/android/maven"
}
离线开发遇到的问题:
在使用react native的Expo框架进行离线编译的时候,依赖通过本地搭建的archiva提供,但是在执行的时候提示找不到okio的jar包,点击错误提示中的地址确能下载到,具体原因未知。
解决办法是使用本地目录的方式:
maven {
url = "file:///d:/xxx/repo"
}
2.找不到R报错
The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':shopify_flash-list', ':stripe_stripe-react-native', ':expo-av', ':react-native-gesture-handler', ...
> Task :app:compileDebugJavaWithJavac FAILED
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainActivity.java:19: 错误: 程序包R不存在
setTheme(R.style.AppTheme);
^
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainActivity.java:39: 错误: 找不到符号
return new ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, new DefaultReactActivityDelegate(
^
符号: 变量 BuildConfig
位置: 类 MainActivity
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:27: 错误: 找不到符号
return BuildConfig.DEBUG;
^
符号: 变量 BuildConfig
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:46: 错误: 找不到符号
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
^
符号: 变量 BuildConfig
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:51: 错误: 找不到符号
return BuildConfig.IS_HERMES_ENABLED;
^
符号: 变量 BuildConfig
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:64: 错误: 找不到符号
if (!BuildConfig.REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS) {
^
符号: 变量 BuildConfig
位置: 类 MainApplication
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:67: 错误: 找不到符号
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
^
符号: 变量 BuildConfig
位置: 类 MainApplication
C:\Users\Administrator.SC-202308141336\Desktop\my-app\android\app\src\main\java\com\anonymous\myapp\MainApplication.java:71: 错误: 找不到符号
if (BuildConfig.DEBUG) {
^
符号: 变量 BuildConfig
位置: 类 MainApplication
8 个错误
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings
解决办法:
android/build.gradle文件中namespace错误,改成自己正确的包名即可:
namespace "com.myapp"
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString())
}
改成
namespace "com.anonymous.myapp"
defaultConfig {
applicationId "com.anonymous.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString())
}