onionshare / onionshare-android

Android version of OnionShare
https://onionshare.org/
GNU General Public License v3.0
141 stars 16 forks source link

FileNotFoundException when installing tor binaries #90

Closed grote closed 11 months ago

grote commented 11 months ago

So far 4 users affected on Android 12 and 13.

Exception java.io.FileNotFoundException:
  at org.briarproject.onionwrapper.AndroidTorWrapper.installExecutable (AndroidTorWrapper.java:172)
  at org.briarproject.onionwrapper.AndroidTorWrapper.installTorExecutable (AndroidTorWrapper.java:147)
  at org.briarproject.onionwrapper.AbstractTorWrapper.installAssets (AbstractTorWrapper.java:204)
  at org.briarproject.onionwrapper.AbstractTorWrapper.start (AbstractTorWrapper.java:136)
  at org.onionshare.android.tor.TorManager$start$2.invokeSuspend (TorManager.kt:78)
akwizgran commented 11 months ago

This exception is thrown when the library isn't found in the native lib dir and we can't extract it ourselves because SDK_INT >= 29.

If I remember right, the fallback of extracting the library ourselves was copied from Chromium without ever knowing what circumstances would cause the library to be missing from the native lib dir.

I can't see anything special about the phones that would give us a clue - for example they're a mixture of API levels.

By any chance, is the path logged for the FileNotFoundException? Maybe that would give us a clue.

grote commented 11 months ago

Unfortunately, Google Play crash reports don't give us exception messages nor log lines.

grote commented 11 months ago

Ok, so I tried this with a test phone and the google play AAB download and get the same crash. The path there is:

java.io.FileNotFoundException: /data/app/~~CTpaghYtQJOw73fD_uSJEA==/org.onionshare.android-hlQUGSC6tIN-pdXvOMKZyg==/lib/arm64/libtor.so
at org.briarproject.onionwrapper.AndroidTorWrapper.installExecutable(AndroidTorWrapper.java:247)
at org.briarproject.onionwrapper.AndroidTorWrapper.installTorExecutable(AndroidTorWrapper.java:15)
at org.briarproject.onionwrapper.AbstractTorWrapper.start(AbstractTorWrapper.java:91)
at org.onionshare.android.tor.TorManager$start$2.invokeSuspend(TorManager.kt:104)
at org.onionshare.android.tor.TorManager$start$2.invoke(TorManager.kt:2)
at org.onionshare.android.tor.TorManager$start$2.invoke(TorManager.kt:1)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:5)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:72)
at org.onionshare.android.tor.TorManager.start(TorManager.kt:9)
at org.onionshare.android.ShareManager$startSharing$2$1$torTask$1.invokeSuspend(ShareManager.kt:33)

I am afraid that this is an app bundle issue maybe affecting all users of the official release.

akwizgran commented 11 months ago

Yikes. Can we revert to APK releases until we solve it?

akwizgran commented 11 months ago

https://stackoverflow.com/questions/56551036/native-libraries-not-found-in-applicationinfo-nativelibrarydir-when-building-app

You can choose to revert to the original APK behaviour, and this can be done by adding the flag android.bundle.enableUncompressedNativeLibs=false in your gradle.properties file.

grote commented 11 months ago

I downloaded the AAB from Google Play and there's a libtor.so in /base/lib/arm64-v8a/.

https://stackoverflow.com/questions/56551036/native-libraries-not-found-in-applicationinfo-nativelibrarydir-when-building-app

If the native libraries are loaded by a third party library you're depending on, consider filing a bug for them to address this issue so they follow the same logic as the platform.

;)

So should we call System.loadLibrary in Onionwrapper?

akwizgran commented 11 months ago

We don't want to load the executable as a library, so let's try the enableUncompressedNativeLibs approach.

akwizgran commented 11 months ago

Feel free to file a bug against OnionWrapper, although I suggest we don't fix it before arti. ;-)

grote commented 11 months ago

Looks like the gradle property is deprecated and now we need to do:

android {
    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
}

Trying a release with this now.

grote commented 11 months ago

Feel free to file a bug against OnionWrapper, although I suggest we don't fix it before arti. ;-)

Should we add least add this to the README?

grote commented 11 months ago

It appears that you can't really test this before Google hasn't published the release. While I can download a signed universal APK, this one doesn't exhibit the problem found in production. The AAB itself can't get installed. The individual APK splits that Google is installing in production can't be downloaded. At least, I didn't find where.

grote commented 11 months ago

Ok Google is fast these days. This fixed the issue.