12

I am having a strange problem with proguard and kotlin. I am gradually converting a proguarded project to kotlin - which went very fine so far but I am getting proguard errors when converting certain classes. I could not yet isolate what the special property of these classes is so it breaks - they seems to be no different than the other ones. As an example InputStreamWithSource is just:

package org.ligi.passandroid.model

import java.io.InputStream

class InputStreamWithSource(val source: String, val inputStream: InputStream)

and it completely works in the IDE - I can deploy to a device - also all UI tests are running fine. Just when trying to assembleRelease the project I am getting proguard errors I do not understand:

Warning: org.ligi.passandroid.ui.FileUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.FileUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.InputStreamProvider: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassImportActivity$ImportAndShowAsyncTask: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassImportActivity$ImportAndShowAsyncTask: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassImportActivity$ImportAndShowAsyncTask: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassImportActivity$ImportAndShowAsyncTask: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassImportActivity$ImportAndShowAsyncTask: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassViewActivityBase$UpdateAsync: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassViewActivityBase$UpdateAsync: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.PassViewActivityBase$UpdateAsync: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.SearchPassesIntentService: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController$InputStreamUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController$InputStreamUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController$InputStreamUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassController$InputStreamUnzipControllerSpec: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassDialog: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassDialog: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassDialog$1AlertDialogUpdater: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource
Warning: org.ligi.passandroid.ui.UnzipPassDialog$1AlertDialogUpdater: can't find referenced class org.ligi.passandroid.model.InputStreamWithSource

when I add a dontwarn for these classes in the proguard configuration than it crashes at runtime - so these classes are really removed - but they should not be removed as they are used.

I can work around this problem by adding keep class/enum for these classes in the proguard-config - but the question is why this is needed for these classes - IMHO it should not be needed

Anyone has some Idea what could cause this or how best to investigate this problem? The full source is here: https://github.com/ligi/PassAndroid

ligi
  • 39,001
  • 44
  • 144
  • 244

1 Answers1

1

I would make sure that I have my own package defined in proguard - something like this:

-dontwarn org.ligi.passandroid.**
-keep class org.ligi.passandroid.** { *; }
Ray Hunter
  • 15,137
  • 5
  • 53
  • 51
  • 3
    If you do that, then there is no point in running proguard at all – Greg Ennis Feb 17 '18 at 14:07
  • 1
    @GregEnnis for you own code that would be fine, since any code that is not used should be deleted from the project. 3rd party code is a different story. – Ray Hunter Feb 18 '18 at 01:49
  • @GregEnnis is right. If you want to use proguard not just for optimisation (what you are likely referring to), but also for obfuscation, then you should not do this as it will leave all your own code as is, clear to read for anyone getting hold of your APK. – ubuntudroid May 15 '19 at 16:52
  • 1
    @ubuntudroid `-keep` means that you are keeping the classes under the package and not having proguard remove them. `Specifies classes and class members (fields and methods) to be preserved as entry points to your code.` https://www.guardsquare.com/en/products/proguard/manual/usage has nothing to do with obfuscating your code. Obfuscation options https://www.guardsquare.com/en/products/proguard/manual/usage#obfuscationoptions – Ray Hunter May 15 '19 at 20:25
  • 1
    @RayHunter I stand corrected - my bad. Thanks for the references! :) – ubuntudroid May 16 '19 at 09:07