我不确定自己在做什么是正确的方法,还是错过了我所做的某些步骤或太多的步骤。我可以从教程,论坛和示例的各种发现中检索到构建APK的方式。同样,我仍然不确定我的构建方式。
我在./android/app
目录中有生成的密钥库文件,以下是我找到并尝试的结果,但我不知道它们之间的区别:
第1步:
> cd android
> gradlew clean
> gradlew assembleRelease
第2步:
> react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
> cd android
> gradlew assembleRelease
步骤3:
> react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
#Go to ".\android\app\src\main\res" and delete all *drawable-xxxx* and *raw* folder if exist
> cd android
> gradlew assembleRelease -x bundleReleaseJsAndAssets
步骤4:
> npx jetify
> cd android
> gradlew clean
> gradlew assembleRelease
步骤5:
# Go to ./android/app/src/main/assets/ and remove `index.android.bundle` file
> react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
> cd .\android\app\src\main\res && if exist "drawable-hdpi" rmdir "drawable-hdpi" /q /s && if exist "drawable-mdpi" rmdir "drawable-mdpi" /q /s && if exist "drawable-xhdpi" rmdir "drawable-xhdpi" /q /s && if exist "drawable-xxhdpi" rmdir "drawable-xxhdpi" /q /s && if exist "drawable-xxxhdpi" rmdir "drawable-xxxhdpi" /q /s && if exist "raw" rmdir "raw" /q /s
> cd..\..\..\..\..\android
> gradlew assembleRelease -x bundleReleaseJsAndAssets
另一方面,我还创建了自己的批处理文件,以使该版本成为APK。该文件将在项目根目录文件夹之前运行一个文件夹。
build-react-native-release.bat:
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
set driveName="%CD:~0,2%"
set currentFolder="%~dp0"
setlocal enableextensions enabledelayedexpansion
set /A count=1
set list=
CD %driveName%
echo ===========================================
for /d %%D in (*) do (
set "listName=%%~f"
set list=%listName%%1
rem echo !listName! !
echo !count!^. %%~D
set /a count+=1
)
echo ===========================================
:startAgain
set choice=
set /p choice=Type in target folder from listing to build release APK (e.g. targetfolder):
if not '%choice%'=='' (
if exist %choice% (
set choice=%choice%
CD %choice%
goto performbuild
)
)
echo Invalid directory name!
goto startAgain
:performbuild
echo Script will start build target APK to release on %choice%...
timeout /t 2 /nobreak>nul
cd %currentFolder%%choice%^\android\app\src\main\assets
del "index.android.bundle" 2>nul
cd %currentFolder%%choice%
call react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
rem start "" %currentFolder%%choice%^\android\app\src\main\res
timeout /t 2 /nobreak>nul
cd %currentFolder%%choice%^\android\app\src\main\res
echo Validating duplicating resources
if exist "drawable-hdpi" rmdir "drawable-hdpi" /q /s 2>nul
if exist "drawable-mdpi" rmdir "drawable-mdpi" /q /s 2>nul
if exist "drawable-xhdpi" rmdir "drawable-xhdpi" /q /s 2>nul
if exist "drawable-xxhdpi" rmdir "drawable-xxhdpi" /q /s 2>nul
if exist "drawable-xxxhdpi" rmdir "drawable-xxxhdpi" /q /s 2>nul
if exist "raw" rmdir "raw" /q /s 2>nul
cd %currentFolder%%choice%^\android
call gradlew assembleRelease
cd %currentFolder%%choice%
:choiceOpt
set /P answ=Build complete. Do you want to rebuild again[Y/N]?
if /I "%answ%" EQU "Y" goto :performbuild
if /I "%answ%" EQU "N" goto :justexit
goto :choiceOpt
:justexit
echo Exiting
timeout /t 2 /nobreak>nul
exit
创建的这个APK.\android\app\build\outputs\apk\release
是我们将传递给APK进行验证的APK吗?
因此,最后看看您希望将已签名的APK /捆绑包上传到您的Playstore。为此,正如您所提到的,所有步骤最后都执行相同的操作。创建签名的APK:
以下步骤非常适合您遵循:
1.创建一个更新的js包,因为其中包含您的最新代码。这样做是为了更新您的响应本机代码包。请检查您的捆绑文件是否已命名index.android.bundle
或仅index.bundle
在android/app/src/main/assets
目录中。
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
2.Android X之后,您想要迁移与android x兼容的所有依赖项。在您的本机目录中执行以下操作:
yarn add jetifier
或npm i jetifier
然后
npx jetify
3.完成后,导航到android目录cd android
并执行清理操作,这将清理所有现有的构建:
./gradlew clean
之后,您可以在android目录中创建APK或捆绑包。您可以将两者都上传到Playstore。但我建议使用捆绑软件,因为它可以大大减少应用程序的大小。
一种。建立APK:./gradlew assembleRelease
并在/android/app/build/outputs/apk/
b中建立一个APK 。建立bundle:'./gradlew bundleRelease
并在b中建立一个bundleandroid/app/build/outputs/bundle/
您可以共享APK或上传它,但不能共享捆绑包,您只能将捆绑包上传到Playstore。
希望能帮助到你。毫无疑问
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句