Jerry Agin
Jerry Agin

Reputation: 719

Signed APK contains different code from debug version

I recently updated an app in the Play store. When I started to get many bug reports, I investigated and found that the APK that was published did not correspond to the .java files in the module. In particular, the version of class MainActivity that was in the signed APK was a buggy version that I had updated weeks ago.

When I ran my app, using Android Studio, through a USB connection in debug mode, it performed correctly. When I used Android Studio to make a signed APK of the same code and side-loaded it onto my test device, it exhibited the buggy behavior from the old version.

Fortunately I had Android Studio on another computer, a laptop. I copied the src/ directory to the laptop and created the signed APK on the laptop. That APK worked correctly, and I was able to publish the updated APK produced on the laptop.

Why is Android Studio using an outdated copy of one of my class files?

Upvotes: 0

Views: 967

Answers (3)

Sergey Shustikov
Sergey Shustikov

Reputation: 15831

Why is Android Studio using an outdated copy of one of my class files?

You are right. This sometimes happens also for me. Long time ago I stuck with the same problem. This happens because AS use Gradle for build.

Gradle may optimize some steps to create signed APK in fast way, he using copies of files that doesn't changed for speed up process. So if you need to be sure that you have a correct build you need cleanup your project and build again.

Upvotes: 1

zerobandwidth
zerobandwidth

Reputation: 1303

Always use a "clean" build for signed APKs to avoid use of cached .class files. Also, if this is an update, you should ensure that you are incrementing the version number of your app in your build.gradle file.

Upvotes: 1

Vesko
Vesko

Reputation: 3760

Strange behaviour indeed. Although I agree sometimes (read rarely) Android Studio files get messed up, in my experience it's usually some of the following problems:

  1. Proguard -> you mentioned that the DEBUG build works correctly and the RELEASE didn't, not even when you create a new build from Android Studio. I'd double-check if a Proguard configuration was changed and that all settings are correct.

  2. Human mistake -> those things just happen and it's possible to upload the wrong version to the store. This doesn't explain why your new RELEASE build failed though..

  3. Custom gradle plugins -> it happened to me twice that some plugins were using the wrong hooks, thus messing the build process generally (although I'd expect a failing build, but ...)

Upvotes: 0

Related Questions