pytorch / android-demo-app

PyTorch android examples of usage in applications
1.45k stars 596 forks source link

Fix crash when minifyEnabled=true #269

Open COO1M opened 1 year ago

COO1M commented 1 year ago

Fix: #266 #165 In Android APP projects, minifyEnabled is usually set to true in the release version to enable Proguard. But when minifyEnabled=true, LiteModuleLoader.load() will crash, I guess it should be caused by Proguard's obfuscation. It can be reproduced in the HellowWorld demo, you can try it in other demos, the following is my environment configuration:

Gradle Plugin Version: 7.3.0
Gradle Version: 7.5.1
JDK: 11

compileSdkVersion: 33
buildToolsVersion: 33.0.0
ndkVersion: 25.1.8937393
minSdkVersion: 21
targetSdkVersion: 33

org.pytorch:pytorch_android_lite: 1.12.2
org.pytorch:pytorch_android_torchvision_lite: 1.12.2

So I tried to find the official proguard rules from the demo, but I couldn't find them, so I added rules for org.pytorch.*, com.facebook.* to avoid them being obfuscated. It works both in my APP and in the HellowWorld demo. Of course, it would be better if you could give more accurate Proguard rules, looking forward to your reply.