9

我正在使用 Ionic 构建一个混合应用程序。我最近尝试将 Ionic 应用程序构建到 Android 应用程序中,但在ionic run android连接设备运行时出现以下错误:

Running command: /Users/USERNAME/Sites/PROJECT/egenius-client-application/hooks/after_prepare/010_add_platform_class.js /Users/USERNAME/Sites/PROJECT/egenius-client-    application
add to body class: platform-android
ANDROID_HOME=/Users/USERNAME/Library/Developer/android-sdk-macosx
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
No target specified, deploying to device 'F7NPFP131245'.
:preBuild UP-TO-DATE
:preDebugBuild UP-TO-DATE
:checkDebugManifest
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugRenderscript
:CordovaLib:generateDebugResValues
:CordovaLib:generateDebugResources
:CordovaLib:packageDebugResources
:CordovaLib:compileDebugAidl
:CordovaLib:generateDebugBuildConfig
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets
:CordovaLib:processDebugManifest
:CordovaLib:processDebugResources
:CordovaLib:generateDebugSources
:CordovaLib:compileDebugJavaWithJavacNote: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

:CordovaLib:processDebugJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForDebug
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug
:CordovaLib:mergeDebugJniLibFolders
:CordovaLib:transformNative_libsWithMergeJniLibsForDebug
:CordovaLib:transformNative_libsWithSyncJniLibsForDebug
:CordovaLib:bundleDebug
:prepareAndroidCordovaLibUnspecifiedDebugLibrary
:prepareDebugDependencies
:compileDebugAidl
:compileDebugRenderscript
:generateDebugBuildConfig
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets
:generateDebugResValues
:generateDebugResources
:mergeDebugResources
:processDebugManifest
:processDebugResourceszs
:generateDebugSources
:compileDebugJavaWithJavacNote: /Users/alexandermcintosh/Sites/eGenius/egenius-client-application/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.    java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

:compileDebugNdk UP-TO-DATE
:compileDebugSources
:transformClassesWithDexForDebug
:mergeDebugJniLibFolders
:transformNative_libsWithMergeJniLibsForDebug
:processDebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForDebug
:validateDebugSigning
:packageDebug
:zipalignDebugUnable to open '/Users/USERNAME/Sites/PROJECT/egenius-client-application/platforms/android/build/outputs/apk/android-debug-unaligned.apk' as zip archive
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':zipalignDebug'.
> Process 'command '/Users/USERNAME/Library/Developer/android-sdk-macosx/build-tools/23.0.2/zipalign'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2 mins 35.63 secs
ERROR running one or more of the platforms: Error code 1 for command: /Users/USERNAME/Sites/PROJECT/egenius-client-application/platforms/android/gradlew with args:     cdvBuildDebug,-b,/Users/USERNAME/Sites/PROJECT/egenius-client-application/platforms/android/build.gradle,-PcdvBuildArch=x86,-Dorg.gradle.daemon=true,-Pandroid.    useDeprecatedNdk=true
You may not have the required environment or OS to run this project

看来我可以很好地构建,运行ionic build android --release可以毫无问题地工作,这是我必须使用 ZipAlign 工具的时候。

像这样手动运行该工具:~/Library/Developer/android-sdk-macosx/build-tools/23.0.2/zipalign -v 4 android-release-unsigned.apk egenius-app.apk告诉我:Unable to open 'android-release-unsigned.apk' as zip archive.

我尝试将我的 SDK 降级到不同的版本,卸载并重新安装插件,但我没有被卡住,在线查找并没有提供很多帮助。

有谁知道我错过了什么?

谢谢,亚历克斯。

更新 当我删除了应用程序构建并成功签名的依赖Angular Material Design Icons的那一刻。

4

6 回答 6

7

当未签名的 apk 与 zipalign 文件不在同一目录时,我遇到了错误。

我通过放置未签名 apk 的文件路径来修复该问题

./zipalign -v 4 /Users/mj/Projects/Ionic/myApp/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk my-signed-release.apk
于 2019-04-30T10:03:08.770 回答
2

尝试

ionic cordova plugin rm cordova-plugin-console 

然后重新运行构建、keytool 和 jarsigner

于 2017-08-07T13:50:51.837 回答
2

我有同样的问题,我尝试使用以下命令

zipalign -v 4 /User/ionictutes/myioncApp/app-release-unsigned.apk appname.apk

于 2019-08-23T05:42:35.700 回答
1

你必须先用 jarsigner 签名。然后你就可以压缩它了。

快速解释:

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

首先会提示您为密钥库创建密码。然后,回答好工具的其余问题,当一切都完成后,您应该在当前目录中创建了一个名为 my-release-key.keystore 的文件。

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name

在此过程之后,您应该能够:

zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk
于 2016-02-10T13:09:15.947 回答
0

我遇到了同样的问题,并使用完整的路径为我工作。

例如:

zipalign -v 4 /Users/rafaelsantiago/app/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk app.apk

于 2020-04-30T00:02:23.623 回答
0

今天我在我的 Mac OS 中遇到了同样的问题,我通过以下步骤解决了这个问题。

  1. android-release-unsigned.apk首先我从路径复制:

    /Applications/XAMPP/xamppfiles/htdocs/Old Projects/kcformulas-2020/mesh-formula/platforms/android/build/outputs/apk/release/android-release-unsigned.apk
    

    到我当前的 Ionic Project 文件夹,即

    /Applications/XAMPP/xamppfiles/htdocs/Old Projects/kcformulas-2020/mesh-formula 
    
  2. 之后我运行以下命令:-

    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore android-release-unsigned.apk mesh_formula
    
  3. 之后,我通过给出 zipalign 的完整路径来运行以下命令,如下所示:-

    /Users/amitgupta/Library/Android/sdk/build-tools/29.0.2/zipalign -v 4 android-release-unsigned.apk KCMeshFormula.apk
    

    采取上述步骤后,我的 APK 成功生成。

希望它将来对某人有所帮助。

于 2020-01-06T01:17:24.930 回答