So I connected a library in the city which, as I understood from the description, will delete everything that is not used in the project from my apk file.

I added such lines

 buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } 

But the getDefaultProguardFile method underlines and writes that it cannot recognize it ... I googled and realized that this problem exists ...

I tried the method that is recommended

 "File" -> "Invalidate Caches..." 

But for me it did not work. I understand that now proguard does not work at all ...

Tell me what to do to make it work correctly?

If by the way do so

 buildTypes { release { shrinkResources true minifyEnabled true // proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), // 'proguard-rules.pro' proguardFiles 'proguard-rules.pro' } } 

It does not emphasize anything, but how, in this case, does it work or not?

  • Eclipse works exactly. May need to specify the path to the file proguard-android-optimize.txt - Oleg A
  • @ OlegA Any ideas how to do this? I'm not at all sure that this file exists ... - Aleksey Timoshchenko
  • @OlegA and how can I check whether it works or not? Should the apk file size be smaller? - Aleksey Timoshchenko
  • Well, what does "less" mean, do you have a lot of unused classes there? I proguard yuzayu for obfuscation. And you can check by taking, for example, JaDX, or some other decompiler, and see what happened in the inside. The file proguard-android-optimize.txt is in / sdk / tools / proguard - Oleg A
  • @OlegA And you can still tell ... So I took the Dexplorer decompiler Dexplorer open my application, and there are no classes open at all, only AppInfo although I do not have this class ... A manifest is available and drawable resources ... What can this mean? I understand that this is just the proguard settings proguard limit access to java files? - Aleksey Timoshchenko

1 answer 1

Change # 1

Но метод getDefaultProguardFile подчеркивает и пишет, что не может распознать его... Я загуглил и понял, что это проблема существует...

As I understand your "underscore" , you mean a message like "cannot resolve symbol". This is normal for Gradle! I will study your question and add an answer a little later.

Change # 0

The fact that you have zakommencheno there is a file of settings proguard, where you specify by what principle it is necessary for it to work. (Which libraries to skip, where not to take into account varnings, etc.). To check whether it works or not, you must first enable it (and you have it turned on), specify the settings file, and secondly try to compile the program and compile .apk. If .apk met successfully - I congratulate you! If not, then learn what logs the gradle sent you and try to change something (usually, errors are related to the use of libraries).

  • So the fact is that the file was compiled before, everything works ... I just had a question because I noticed that getDefaultProguardFile shows that this method is not recognized ... I just commented on this line and put another one and everything compile without errors. That's why I want to check it really works? Since there were no errors for the first time either, but the method was not recognized - it probably didn't work. - Aleksey Timoshchenko
  • I've added another answer in the comments to the question, I understand it correctly? - Aleksey Timoshchenko 4:47 pm