LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS
MIT License
1.02k stars 128 forks source link

couldn't find "libflutter.so" #91

Closed bangonkali closed 5 years ago

bangonkali commented 5 years ago

Greate library so far! But im getting a weird behaviour for which I made a simple repo to demonstrate this fact.

Behavior: Builds and runs using flutter run but fails using Android Studio debug. See an error on the bottom. Gist of error is couldn't find "libflutter.so".

I use flutter primarily on my UI front end and Kotlin as backend all on Android.

Flutter project was created using the following command:

flutter create -i swift -a kotlin --org "com.namespace" --description "desc" --project-name "projectname" "outputdir"

Output should be roughtly similar to this commit.

You can run the generated sample code from both VS Code Flutter extension and Android Studio by opening the android folder as an android project.

After adding the deps as commit here, the project no longer works using Android Studio as the Build then Run Platform.

Any ideas?

2019-03-23 11:58:02.458 11803-11803/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2019-03-23 11:58:02.458 11803-11803/? E/Zygote: accessInfo : 1
2019-03-23 11:58:02.462 11803-11803/? I/alado.filo.fil: Late-enabling -Xcheck:jni
2019-03-23 11:58:02.487 11803-11803/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
2019-03-23 11:58:02.508 11803-11803/? W/ActivityThread: Application ph.com.regalado.filo.filo is waiting for the debugger on port 8100...
2019-03-23 11:58:02.510 11803-11803/? I/System.out: Sending WAIT chunk
2019-03-23 11:58:02.526 11803-11812/? E/alado.filo.fil: Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe
2019-03-23 11:58:04.512 11803-11803/ph.com.regalado.filo.filo I/System.out: Debugger has connected
2019-03-23 11:58:04.512 11803-11803/ph.com.regalado.filo.filo I/System.out: waiting for debugger to settle...
2019-03-23 11:58:05.113 11803-11803/ph.com.regalado.filo.filo I/chatty: uid=10245(ph.com.regalado.filo.filo) identical 3 lines
2019-03-23 11:58:05.313 11803-11803/ph.com.regalado.filo.filo I/System.out: waiting for debugger to settle...
2019-03-23 11:58:05.514 11803-11803/ph.com.regalado.filo.filo I/System.out: waiting for debugger to settle...
2019-03-23 11:58:05.714 11803-11803/ph.com.regalado.filo.filo I/System.out: waiting for debugger to settle...
2019-03-23 11:58:05.919 11803-11803/ph.com.regalado.filo.filo I/System.out: debugger has settled (1341)
2019-03-23 11:58:06.076 11803-11829/ph.com.regalado.filo.filo I/ResourceExtractor: Resource version mismatch res_timestamp-1-1553312145969
2019-03-23 11:58:06.083 11803-11803/ph.com.regalado.filo.filo D/AndroidRuntime: Shutting down VM
2019-03-23 11:58:06.095 11803-11803/ph.com.regalado.filo.filo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ph.com.regalado.filo.filo, PID: 11803
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ph.com.regalado.filo.filo-ZBc8glziP0Bg9RzzOWkiCQ==/base.apk"],nativeLibraryDirectories=[/data/app/ph.com.regalado.filo.filo-ZBc8glziP0Bg9RzzOWkiCQ==/lib/arm64, /data/app/ph.com.regalado.filo.filo-ZBc8glziP0Bg9RzzOWkiCQ==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libflutter.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
        at java.lang.System.loadLibrary(System.java:1669)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:156)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:133)
        at io.flutter.app.FlutterApplication.onCreate(FlutterApplication.java:22)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6204)
        at android.app.ActivityThread.access$1200(ActivityThread.java:236)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1784)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7032)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
2019-03-23 11:58:06.113 11803-11803/? I/Process: Sending signal. PID: 11803 SIG: 9
ericwlange commented 5 years ago

Are you using the flutter_liquidcore module? @j0j00 developed that extension for flutter and may be able to help. I haven't worked with flutter, yet, so it would be a learning curve for me.

bangonkali commented 5 years ago

hi @ericwlange i haven't tried using fluter_liquidcore. my use case is rather different because the v8 engine has to be on the android layer - communicating only with the flutter layer over mqtt because it's currently written as an android service running on a different process. the flutter layer is purely for ui presentation but the backend should survive closing of the app, and hence written as a service on a separate process.

ericwlange commented 5 years ago

When you look at the contents of your APK, what does it look like? In Android Studio, Build -> Analyze APK and select your built APK. E.g., for one of mine (with the expanded lib/x86_64 directory):

Screen Shot 2019-03-23 at 11 18 15 AM

Is libflutter.so present?

bangonkali commented 5 years ago

Unfortunately this is the only thing i see. image

this one runs but fails on startup with missing flutter.so as error on issue.

but if i comment out

// app/build.gradle
...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // implementation 'com.github.LiquidPlayer:LiquidCore:0.6.0'
}
...

then i see a build named outputs/apk/debug/app-debug.apk

and this is the result

image

this on renders out flutter well.

as this might help:

build with the extension it seems this is the apk that is produced:

outputs/apk/debug/app-arm64-v8a-debug.apk

build without the extension it seems there is a different apk that is produced:

outputs/apk/debug/app-debug.apk

the phone i use for testing is Samsung Galaxy S10

and the contents of app/build.gradle is

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "ph.com.regalado.filo.filo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // implementation 'com.github.LiquidPlayer:LiquidCore:0.6.0'
}

build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "ph.com.regalado.filo.filo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // implementation 'com.github.LiquidPlayer:LiquidCore:0.6.0'
}
bangonkali commented 5 years ago

okay, so i redid the whole thing this time doing the following before building.

  1. clean up build dir using flutter clean
  2. on android studio i did a build -> clean project

and this is what i got.

image

if feels like i'm very close 🤣 it just seems, arm64-v8a has no flutter.so but the rest has it.

ericwlange commented 5 years ago

That's so strange! I'm so sorry that I can't really help much, since I haven't even tried flutter yet. But it does seem like you're on the right track. I am happy to see that libliquidcore.so and libnode.so are there, though! Those are all you need for LiquidCore to work.

bangonkali commented 5 years ago

hi @ericwlange your guidance has been instrumental. it seems the solution for flutter + ndk related modules is this.

        ndk {
            if (project.hasProperty('target-platform') &&
               project.property('target-platform') == 'android-arm64') {
                abiFilters 'arm64-v8a'
            } else {
                abiFilters 'armeabi-v7a'
            }
        }

VS Cod extension seems to know exactly what device to build against. Hence it's building x64 version. image

regarding my initial post, it runs on VSCODE, because flutter build considered the output. lower right corner of the above screenshot. flutter.so is build on 64bit but 64 bit only. as discussed here.

apk analysed here image

When building using default build config from Android Studio, it builds flutter.so for all except 64bit version as shown here. image

the fix was this.

https://github.com/flutter/flutter/issues/18494#issuecomment-475732536

i am closing this as my issue is resolved and it was never a liquidcore issue in the first place. the flutter guys are probably going to do something about it someday.

thank you very much for your superb support! highly appreciated!!! 👍👍👍

also i now know how to use analyze apk 🤣🤣🤣