3

I'm having trouble running the vitamio-sample from https://github.com/yixia/VitamioBundle.

I am building it with Android Studio and it compiles fine and runs, but when it gets to this line:

if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
    return;

It throws an exception when I run it on my Nexus 5 (and also on a Galaxy S4):

01-22 11:58:40.759  12323-12323/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: io.vov.vitamio.demo, PID: 12323
java.lang.UnsatisfiedLinkError: Couldn't load vinit from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.vov.vitamio.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/io.vov.vitamio.demo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:358)
        at java.lang.System.loadLibrary(System.java:526)
        at io.vov.vitamio.Vitamio.<clinit>(Vitamio.java:258)
        at io.vov.vitamio.LibsChecker.checkVitamioLibs(LibsChecker.java:40)
        at io.vov.vitamio.demo.VitamioListActivity.onCreate(VitamioListActivity.java:40)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

The exception also happens when I'm running the v4.2.0 tree in my own app.

Any idea what I'm missing? In my own app I pulled the vitamio project into a libraries folder and am referencing it like this:

     compile(project(':libraries:vitamio'))

The sample project is left as-is.

Paul
  • 4,422
  • 5
  • 29
  • 55
  • Check this http://stackoverflow.com/questions/20117884/android-studio-app-with-library-project-fails-to-build – Zohra Khan Jan 22 '14 at 17:44
  • remove ( from compile line compile project(':libraries:vitamio') . Make sure to clean your project Build->clean project or ./gradlew clean – Zohra Khan Jan 22 '14 at 17:48
  • It's building correctly, it just doesn't look like it's copying over the so files in the right spot. – Paul Jan 22 '14 at 17:53
  • There are lots of post which says that there is some bug in Android Studio and it will be fixed in 0.4.3. – Zohra Khan Jan 22 '14 at 17:59
  • Yes -- the ( ) are optional there in groovy so it does the same thing. I'm looking around and I see that .so files in gradle are not supported in the version of Android Studio I'm using (0.3.2). I will look into upgrading to 0.4.2 to see if that helps. – Paul Jan 22 '14 at 17:59
  • After upgrade, try these things.1. Before importing delete the content of .idea directory inside your project2.Change your gradle to 0.7+ in build.gradle. Hope it will help you. – Zohra Khan Jan 22 '14 at 18:02
  • 1
    @ShyGuy, I think you're right, and it's because the .so isn't getting bundled in the APK. There's NDK support in the later versions of the Android plugin (which you'll need to use if you upgrade Android Studio, and vice-versa), so upgrade first, and if you're still having problems, post your build.gradle file. – Scott Barta Jan 23 '14 at 23:54
  • 1
    @ShyGuy Android gradle plugin version 8 support prebuild lib project, Please update the version 8. or try build sample project. – Crossle Song Feb 09 '14 at 09:20
  • @ShyGuy have you solved the issue? im facing this on my emulator of android 4.4.2 – Qadir Hussain Jun 11 '14 at 05:13
  • @QadirHussain I included an answer which I ended up getting to work. Unfortunately I have not tried it with a newer version of gradle so I don't know if there's an easier way (or if this will work with it). – Paul Jun 11 '14 at 15:15
  • @ShyGuy can I stream vedio using Vitamio Library on Intel x86 Emulator? – Qadir Hussain Apr 15 '15 at 07:10

1 Answers1

2

I am not sure if there is a cleaner way in the newer version of Vitamino (or gradle). But here is how I got it to work with gradle build tools 0.6.

  1. Added a project to my /libraries directory with the vitamino source/sdk. This has a /libs/armeabi /libs/armeabi-v7a with libvinit.so inside.

  2. In my build.gradle for my main project, reference the library project like:

    dependencies {
    
        // other dependencies 
    
        compile(project(':libraries:vitamio'))
    
    }
    
  3. Add the following to the bottom of my build.gradle

    task copyNativeLibs(type: Copy) {
        from(new File(project(':libraries:vitamio').getProjectDir(), 'libs')) { include '**/*.so' }
    into new File(buildDir, 'native-libs')
    }
    
    tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
    
    clean.dependsOn 'cleanCopyNativeLibs'
    
    tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
        pkgTask.jniDir new File(buildDir, 'native-libs')
    }
    

Then when i run a clean and rebuild it will copy the native libs to the proper spot and include them in the build.

Paul
  • 4,422
  • 5
  • 29
  • 55
  • can I stream vedio using Vitamio Library on Android Intel x86 Emulator? – Qadir Hussain Apr 15 '15 at 07:10
  • Could not find method jniDir() for arguments [D:\Android WorkSpace\Androidapp\app\build\native-libs] on task ':app:packageDebug' of type com.android.build.gradle.tasks.PackageApplication. – Web.11 Jan 27 '19 at 20:50