Open dvagala opened 1 year ago
Okay, so it turned out the shrinkResources
needs to be false
. I'm not sure if it can be properly fixed, but maybe it would be good to have that in the example project, and in readme.
Quick fix In project's android/app/build.gradle
buildTypes {
release {
shrinkResources false
...
}
}
Dont forget to also add
minifyEnabled false
Does anybody know how to use proguard to infer in release with minifyEnabled and shrinkResources set to true without this crash?
Here is what worked for me adapting files in my project.
In android/app/build.gradle
:
android {
...
buildTypes {
...
release {
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
...
In android/app/proguard-rules.pro
:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-keep class org.pytorch.** { *; }
-keep class com.facebook.jni.** { *; }
Static analysis of release apk with MobSF shows my code is still obfuscated.
I don't get no crash anymore.
Inference works as expected on android release app.
When using release build the app is crashing on startup. Tested on Flutter versions
2.5.0 2.8.1 3.3.8
Full error
```js WARN: Unable to load JNA library (OS: Mac OS X 13.0) java.lang.UnsatisfiedLinkError: /Users/dvagala/Library/Caches/JNA/temp/jna3185256063644712833.tmp: dlopen(/Users/dvagala/Library/Caches/JNA/temp/jna3185256063644712833.tmp, 0x0001): tried: '/Users/dvagala/Library/Caches/JNA/temp/jna3185256063644712833.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/dvagala/Library/Caches/JNA/temp/jna3185256063644712833.tmp' (no such file), '/Users/dvagala/Library/Caches/JNA/temp/jna3185256063644712833.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')) at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method) at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442) at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498) at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694) at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2627) at java.base/java.lang.Runtime.load0(Runtime.java:768) at java.base/java.lang.System.load(System.java:1837) at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018) at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988) at com.sun.jna.Native.