2

我试图将我的项目组装为一个版本。但它总是失败。以下是我用来将我的 apk 构建为发行版的一些脚本:-

构建成功

.\gradlew assembleDebug --no-daemon
.\gradlew app:assembleDebug

构建失败

.\gradlew app:assembleRelease
.\gradlew assembleRelease -x bundleReleaseJsAndAssets

每次失败构建失败提及的结果:-

> Execution failed for task ':app:mergeReleaseResources'
> Task :app:mergeReleaseResources
> FAILED cvc-type.3.1.3: The value '' of element 'id' is not valid.

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

我也尝试使用 keytool 创建密钥库并将其signingConfigs应用于

./android/app/build.gradle

但发布没有成功。所以,我正在恢复并使用默认debug.keystore

参考论坛,SO问题,教程的各种答案,我尝试申请。我完全被困住了。

有没有人面临这个问题并能够克服障碍?

已编辑:构建时的错误日志

使用.\gradlew assembleRelease

D:\Project\Clients\android>.\gradlew assembleRelease

> Configure project :react-native-activity-result
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.

> Task :react-native-activity-result:verifyReleaseResources FAILED

> Task :app:bundleReleaseJsAndAssets
Loading dependency graph, done.
info Writing bundle output to:, D:\Project\Clients\android\app\build\generated\assets\react\release\index.android.bundle
info Writing sourcemap output to:, D:\Project\Clients\android\app\build\intermediates\sourcemaps\release\index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 47 asset files
info Done copying assets

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-activity-result:verifyReleaseResources'.
> 1 exception was raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
  error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:7: error: resource android:attr/colorError not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:11: error: resource android:attr/colorError not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:15: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2734: error: resource android:attr/fontStyle not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2735: error: resource android:attr/font not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2736: error: resource android:attr/fontWeight not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2737: error: resource android:attr/fontVariationSettings not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2738: error: resource android:attr/ttcIndex not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2902: error: resource android:attr/startX not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2905: error: resource android:attr/startY not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2908: error: resource android:attr/endX not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2911: error: resource android:attr/endY not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2919: error: resource android:attr/offset not found.
  error: failed linking references.



* 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 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 54s
210 actionable tasks: 22 executed, 188 up-to-date

D:\Project\Clients\android> 
4

3 回答 3

0

我终于可以创建发布 APK

  1. 通过运行命令创建密钥库keytool -genkey -v -keystore myappkeystore.keystore -alias myappalias-keyalg RSA -keysize 2048 -validity 10000并将其放在.\android\app. 详细说明可以从这里开始
  2. 打开名为build.gradle的文件并查找部分名称signingConfigs
  3. 在调试键名后插入以下脚本并替换为您注册的键:-

    release {
        storeFile file('mycreatedkeystore.keystore')
        storePassword 'mypassword'
        keyAlias 'mykeyalias'
        keyPassword 'mypassword'
    }
    
  4. 打开空白记事本并粘贴以下脚本:-

    @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
    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
    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 %currentFolder%%choice%^\android
    call gradlew assembleRelease -x bundleReleaseJsAndAssets
    start "" %currentFolder%%choice%^\android\app\build\outputs\apk\release"
    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
    
  5. 以任意名称保存文件并将扩展名设置为.BAT

  6. 将 BAT 文件放在根项目的一个文件夹中,例如

    • 您的项目文件夹:- C:\Project\Mobile\MyCurrentProject

    • 您的批处理文件夹:- C:\Project\Mobile\releaseTool.bat

  7. 运行releaseTool.bat批处理文件并构建发布版本

我搜索并找到了几个脚本来完成某些 oart 并将其组合为 RELEASE APK 版本的批处理脚本

免责声明:我不是详细说明过程或争论我正在做的方式的专家(如果它不切实际),因为我未能构建我想要的东西,并且将逐个解决方案组合起来并成为什么我提供了。

于 2020-05-13T03:51:32.293 回答
0

在某些反应本机版本中,这是一个错误。您可以执行以下操作:

node_modules/react-native文件夹中,找到react.gradle文件,

然后在doFirst添加以下代码之后:

 doLast {
    def moveFunc = { resSuffix ->
        File originalDir = 
    file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
        if (originalDir.exists()) {
            File destDir = 
    file("$buildDir/../src/main/res/drawable-${resSuffix}");
            ant.move(file: originalDir, tofile: destDir);
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

然后你可以使用./gradlew assembleRelease生成的apk。
同时,在构建过程中想知道errr是什么的时候,可以使用./gradlew assembleRelease --infocommod

于 2019-11-07T04:45:35.207 回答
0

曾经面对这个,这是一个 APPT2 问题(至少在我的情况下)。从共享的屏幕截图中,它告诉您Duplicate resources。这可能发生在您执行 js 捆绑之后,并且创建了几个包含资源的文件夹。

以下是我如何处理 APPT2 问题:

  1. 尝试导航到 (android/app/build/intermediates/res/merged/release/
  2. 看看有没有drawable-*文件夹
  3. 履行rm -rf android/app/build/intermediates/res/merged/release/drawable-*)
  4. 再试一次 ./gradlew assembleRelease (您可能仍然无法在此处构建)
  5. 回到同一个文件夹,删除 .DS_Store
  6. 再次构建
  7. 希望成功
于 2019-11-07T02:23:36.807 回答