Generate Signed APK: Errors While Creating APK Android Studio

I cannot create a Signed APK using minifyEnabled true and shrinkResources true

Application Level: build.gradle

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' } } apply plugin: 'com.android.application' repositories { mavenCentral() } android { compileSdkVersion 23 buildToolsVersion '22.0.1' defaultConfig { applicationId "......." minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { debug { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } configurations { compile.exclude group: "org.apache.httpcomponents", module: "httpclient" } } dependencies { compile 'com.android.support:design:23.0.1' compile 'com.android.support:cardview-v7:23.0.1' compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.google.apis:google-api-services-youtube:v3-rev149-1.20.0' compile 'com.google.http-client:google-http-client-android:1.20.0' compile 'com.google.api-client:google-api-client-android:1.20.0' compile 'com.google.api-client:google-api-client-gson:1.20.0' compile files('libs/YouTubeAndroidPlayerApi.jar') compile 'com.github.clans:fab:1.6.2' } 

Messageview

 Information:Gradle tasks [:app:assembleRelease] :app:preBuild UP-TO-DATE :app:preReleaseBuild UP-TO-DATE :app:checkReleaseManifest :app:preDebugBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE :app:prepareComAndroidSupportCardviewV72301Library UP-TO-DATE :app:prepareComAndroidSupportDesign2301Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE :app:prepareComGithubClansFab162Library UP-TO-DATE :app:prepareReleaseDependencies :app:compileReleaseAidl :app:compileReleaseRenderscript :app:generateReleaseBuildConfig :app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets :app:generateReleaseResValues UP-TO-DATE :app:generateReleaseResources :app:mergeReleaseResources :app:processReleaseManifest :app:processReleaseResources :app:generateReleaseSources :app:processReleaseJavaRes UP-TO-DATE :app:compileReleaseJavaWithJavac Note: .....YouTubeRecyclerViewFragment.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: ....GetPlaylistAsyncTask.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. :app:compileReleaseNdk UP-TO-DATE :app:compileReleaseSources :app:proguardRelease UP-TO-DATE :app:dexRelease :app:shrinkReleaseResources Removed unused resources: Binary resource data reduced from 741KB to 402KB: Removed 45% Note: If necessary, you can disable resource shrinking by adding android { buildTypes { release { shrinkResources false } } } :app:validateExternalOverrideSigning :app:packageRelease FAILED Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of ....\app\build\intermediates\classes-proguard\release\classes.jar Information:BUILD FAILED Information:Total time: 7.45 secs Information:1 error Information:0 warnings Information:See complete output in console 
+9
source share
8 answers

You are getting

 Removed unused resources: Binary resource data reduced from 741KB to 402KB: Removed 45% Note: If necessary, you can disable resource shrinking by adding android { buildTypes { release { shrinkResources false } } } :app:validateExternalOverrideSigning :app:packageRelease FAILED Error:Execution failed for task ':app:packageRelease'. 

Resource reduction only works in conjunction with code reduction.

minifyEnabled is an Android tool that will reduce the size of your application when it is created.

 android { buildTypes { release { shrinkResources true // This must be first minifyEnabled true // This must be after shrinkResources proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } 

If you have not already created your application using minifyEnabled to compress code, try this before enabling shrinkResources, as you may need to edit the proguard-rules.pro file to save classes or methods that are created or run dynamically before you start deleting Resources .

Please read the official code and resource reduction guide .

Tip

Use the latest version

 compileSdkVersion 25 buildToolsVersion '25.0.1' targetSdkVersion 25 compile 'com.android.support:appcompat-v7:25.1.0' // set other 25.1.0 

NOTE

 YouTubeRecyclerViewFragment.java uses or overrides a deprecated API. 

Use an alternative latest version.

+10
source

First check if you really need to use shrinkResources

If yes, do as the developers suggested the link https://developer.android.com/studio/build/shrink-code.html#shrink-resources mentioned above IntelliJ Amiya , you should use as below

  android {

     buildTypes {
         release {
             shrinkResources true // - always add this above minifyEnabled -
             minifyEnabled true   
             proguardFiles getDefaultProguardFile ('proguard-android.txt'),
                     'proguard-rules.pro'
         }
     }
 }
+2
source

This :app:proguardRelease UP-TO-DATE .. makes this log not complete enough to say if this answer will help.

Repeat cleanup + build assembly to get a complete log with all steps, you can also add --info options in gradle or even --debug to get more diagnostic messages in gradle build log.

Cleaning + building can also fix some strange problem with a gradle / other tool not updating the file correctly and reusing an earlier wrong one - rarely.

Also try turning off minification OFF (not a solution, just an experiment), whether it helps (to localize the problem really with the help of proguard protection, and not elsewhere).

And, of course, if during minimization there are errors related to proguard, try following the tips of the related answer.

0
source

If you cannot sign apk in Android Studio, manually sign it with

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

if you do not have a key generated with keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

You can also manually subscribe as manual do:

 keytool -genkey -v -keystore my-release-key.jks-keyalg RSA -keysize 2048 -validity 10000 -alias app zipalign -v -p 4 my-app-unaligned.apk my-app.apk apksigner sign --ks my-release-key.jks my-app.apk 

check signed apk

 apksigner verify my-app.apk 
0
source

Try generating a signed APK using the terminal with the gradle command, see the stack trace, which will give you a detailed log where there is a problem.

In windows

$gradle clean

 $ gradle --stacktrace assembleRelease 

In ubuntu

$./gradlew clean

 $./gradlew --stacktrace assembleRelease 

if you still have a problem, you can track the trace here

0
source

R.raw.Keep file (xml file)

 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools" tools:shrinkMode="strict" /> 

Remember to reference this resource from the source .java file. See https://developer.android.com/studio/build/shrink-code.html for details

if you are concerned about the size of your apk file, then its good practice to also reduce image files. This converts the RGB channel into an indexed channel, this can save up to 50% space.

Note: ..... YouTubeRecyclerViewFragment.java uses or overrides the deprecated API.

0
source

Use the Keytool or exe binary key to create a private keystore. See the instructions below. You can then sign your application using this keystore. Keytool installs when you install Java.

http://docs.oracle.com/cd/E19509-01/820-3503/ggfen/index.html

0
source

Clean up the project and start generating the signed Build / Apk again. This works fine for me.

0
source

Source: https://habr.com/ru/post/1261880/


All Articles