Azure / azure-storage-android

Microsoft Azure Storage Library for Android
Apache License 2.0
81 stars 48 forks source link

Unexpected attempt to get register for a value without a register #79

Closed psioukas closed 4 years ago

psioukas commented 4 years ago

Trying to generate a signed apk for release publish in Store. And this error pops-up while building. I have used the implementation dependency method and also with git clone.

Unexpected attempt to get register for a value without a register in methodvoid com.microsoft.azure.storage.CloudStorageAccount.<clinit>().``

This issue is related with minifyEnabled true , and proguard.

bsiegel commented 4 years ago

Can you post the section(s) of your build.gradle file which configure your release build (any sections where you specify "minifyEnabled")? Also let us know what version of the Android SDK & build tools you're using?

I'm almost certain this is an issue with a missing proguard exclusion, so we just need to figure out what needs to be excluded in your case.

psioukas commented 4 years ago

build.gradle file :

apply plugin: 'com.android.application'

android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { ndk { abiFilters "armeabi-v7a", "x86" } applicationId "com.example.AzureExampleProject" minSdkVersion 23 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" proguardFiles packagingOptions { exclude 'META-INF/LICENSE' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { } } }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' //other dependencies implementation project(path: ':microsoft-azure-storage') } repositories { mavenCentral() }

I have inserted this in proguard:

-keep class com.microsoft.azure.storage.CloudStorageAccount -dontwarn micorsoft-azure-storage. -dontwarn com.microsoft.azure.

psioukas commented 4 years ago

Unexpected attempt to get register for a value without a register in method void com.microsoft.azure.storage.CloudStorageAccount.<clinit>(). Error: c:\AppPath\microsoft-azure-storage\build\intermediates\runtime_library_classes\release\classes.jar:com/microsoft/azure/storage/CloudStorageAccount.class, void com.microsoft.azure.storage.CloudStorageAccount.(), Unexpected attempt to get register for a value without a register in method void com.microsoft.azure.storage.CloudStorageAccount.<clinit>().

psioukas commented 4 years ago

Can you post the section(s) of your build.gradle file which configure your release build (any sections where you specify "minifyEnabled")? Also let us know what version of the Android SDK & build tools you're using?

I'm almost certain this is an issue with a missing proguard exclusion, so we just need to figure out what needs to be excluded in your case.

Hey, have you figured if i did anything wrong ?

bsiegel commented 4 years ago

Can you try using proguard-android.txt instead of proguard-android-optimize.txt in your proguardFiles directive and let me know if that resolves your issue? At least that way we can start to focus in on whether the problem is occurring in the minification or the optimization pass.

psioukas commented 4 years ago

Can you try using proguard-android.txt instead of proguard-android-optimize.txt in your proguardFiles directive and let me know if that resolves your issue? At least that way we can start to focus in on whether the problem is occurring in the minification or the optimization pass.

Hello again @bsiegel , thanks for replying. The mentioned change above worked. In the gradle file of the project switched from proguard-android-optimize.txt to proguard-android.txt .And the generation of signed APK was successful.

Can i ask though what is the difference between the two of them? Is there something wrong with the optimization? Is there a way to revert this to proguard-android-optimize.txt and not fail?

bsiegel commented 4 years ago

Okay, great. Proguard optimization on Android is a bit flaky. If you look at the comments at the top of proguard-android.txt you'll see:

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).

# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

If you want to try to get optimization working for your app, you can try switching back to the -optimize rules file and then skip optimizing just the CloudStorageAccount class members. My ProGuard-fu isn't super strong, but I think a rule like the following should work:

-keep class com.microsoft.azure.storage.CloudStorageAccount { *; }

This will exclude the class and all of its members from shrinking, optimization, and renaming. You could also try crafting a more limited exclude that only excludes the <clinit>() method.

psioukas commented 4 years ago

Okay, great. Proguard optimization on Android is a bit flaky. If you look at the comments at the top of proguard-android.txt you'll see:

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).

# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

If you want to try to get optimization working for your app, you can try switching back to the -optimize rules file and then skip optimizing just the CloudStorageAccount class members. My ProGuard-fu isn't super strong, but I think a rule like the following should work:

-keep class com.microsoft.azure.storage.CloudStorageAccount { *; }

This will exclude the class and all of its members from shrinking, optimization, and renaming. You could also try crafting a more limited exclude that only excludes the <clinit>() method.

Thank you. :)