videostream / cordova-chromecast

Chromecast running in Cordova
117 stars 58 forks source link

App crashes on chrome.cast.initialize #7

Open AVGP opened 10 years ago

AVGP commented 10 years ago

First off: Great work! It's about time that Chromecast support becomes available for Cordova :+1:

However, I have trouble getting your plugin to work :(

I set up my Cordova project with the needed library projects in project.properties:

  android.library.reference.1=CordovaLib
  android.library.reference.2=../android/extras/google/google_play_services/libproject/google-play-services_lib
  android.library.reference.3=../android/extras/android/support/v7/appcompat
  android.library.reference.4=../android/extras/android/support/v7/mediarouter

and it compiles just fine. But when I try to use the chrome.cast.* API like this:

  onDeviceReady: function() {
     var sessionRequest = new chrome.cast.SessionRequest("794B7BBF");
     var apiConfig = new chrome.cast.ApiConfig(sessionRequest, function sessionCallback(session) {
      console.log(">> SESSION CALLBACK", session);
    }, function receiverAvailable(recv) {
      console.log(">> RECEIVER AVAILABLE", recv);
    });

    chrome.cast.initialize(apiConfig, function success() {
      console.log(">> INIT SUCCESS");
    }, function error(err) {
      console.log(">> INIT ERR: ", err);
    });
  }

I get the following from adb logcat when I launch the app:

  E/AndroidRuntime( 5759): Process: io.cordova.hellocordova, PID: 5759
  E/AndroidRuntime( 5759): java.lang.NoClassDefFoundError:   android.support.v7.mediarouter.R$string
  E/AndroidRuntime( 5759):  at android.support.v7.media.SystemMediaRouteProvider$JellybeanImpl.<init>(SystemMediaRouteProvider.java:256)
  E/AndroidRuntime( 5759):  at android.support.v7.media.SystemMediaRouteProvider$JellybeanMr1Impl.<init>(SystemMediaRouteProvider.java:716)
  E/AndroidRuntime( 5759):  at android.support.v7.media.SystemMediaRouteProvider$JellybeanMr2Impl.<init>(SystemMediaRouteProvider.java:788)
  E/AndroidRuntime( 5759):  at android.support.v7.media.SystemMediaRouteProvider.obtain(SystemMediaRouteProvider.java:53)
  E/AndroidRuntime( 5759):  at android.support.v7.media.MediaRouter$GlobalMediaRouter.<init>(MediaRouter.java:1410)
  E/AndroidRuntime( 5759):  at android.support.v7.media.MediaRouter.getInstance(MediaRouter.java:166)
  E/AndroidRuntime( 5759):  at acidhax.cordova.chromecast.Chromecast$4.run(Chromecast.java:225)
  E/AndroidRuntime( 5759):  at android.os.Handler.handleCallback(Handler.java:733)
  E/AndroidRuntime( 5759):  at android.os.Handler.dispatchMessage(Handler.java:95)
  E/AndroidRuntime( 5759):  at android.os.Looper.loop(Looper.java:136)
  E/AndroidRuntime( 5759):  at android.app.ActivityThread.main(ActivityThread.java:5017)
  E/AndroidRuntime( 5759):  at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime( 5759):  at java.lang.reflect.Method.invoke(Method.java:515)
  E/AndroidRuntime( 5759):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  E/AndroidRuntime( 5759):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  E/AndroidRuntime( 5759):  at dalvik.system.NativeStart.main(Native Method)
  W/ActivityManager(  598):   Force finishing activity io.cordova.hellocordova/.HelloCordova

Thanks for help troubleshooting this one!

matbee-eth commented 10 years ago

The only thing I can think of is make sure your Google APIs are up to date... That happens when the resource XML's aren't included in the project...

AVGP commented 10 years ago

Hm, unfortunately all libs are updated (acording to the Android SDK updater) and the build succeeds.. I even rechecked, if all the libprojects have the same compile target as the Cordova project

trenkwaldermartin commented 10 years ago

I have the exact same issue. Did you find a solution?

rogerlopess commented 10 years ago

Same problem here. Any solution on this?

AVGP commented 10 years ago

Unfortunately I haven't found a solution to this issue yet.

matbee-eth commented 10 years ago

You have to add those libraries as references! It will not work yet without them.

matbee-eth commented 10 years ago

Just open your project in Eclipse and add the projects

AVGP commented 10 years ago

As stated in the issue, the libraries are in there as library projects, no? Check out the project.properties file I pasted in my first message in this issue. What's wrong there?

AVGP commented 10 years ago

Or could you paste your project.properties - maybe the difference emerges from that.

JudeOsborn commented 10 years ago

Having exactly the same problem. The java dependencies compile fine, but when I try to initialize the chromecast the cordova app crashes.

trenkwaldermartin commented 10 years ago

Ok thank you very much, now it works!! I imported appcompat and mediarouter separately.

AVGP commented 10 years ago

@trenkwaldermartin would you mind explaining in detail what you did that got it working for you?

JudeOsborn commented 10 years ago

@AVGP , I haven't had any success either. However, I did manage to get the "refactor" branch to compile. I haven't gotten Chromecast to connect yet, but it does compile using Cordova library versions of mediarouter, appcompat and play services.

AVGP commented 10 years ago

@JudeOsborn thanks for the heads up. I will give it a go soon then

matbee-eth commented 10 years ago

Just open your project in Eclipse, and add the requirements!

AVGP commented 10 years ago

That's taking a sledgehammer to crack a nut.

Can you please share your project.properties file - at least in excerpt. Because Eclipse is just a few hundred megabytes sugar on top of editing project.properties and running ant.

2014-06-10 18:35 GMT+02:00 Mathieu Gosbee notifications@github.com:

Just open your project in Eclipse, and add the requirements!

— Reply to this email directly or view it on GitHub https://github.com/GetVideostream/cordova-chromecast/issues/7#issuecomment-45638450 .

AVGP commented 10 years ago

What ill-conceived sorcery is this... -_- but thanks for the heads up. It makes me sad to see Google build such black magic. Am 12.06.2014 06:30 schrieb "Jude Osborn" notifications@github.com:

I imported the three libraries via eclipse and finally got them to work. However, the results are the same as the "refactor" branch. Everything seems to load okay, but when initializing I get this error:

W/System.err( 7029): java.lang.reflect.InvocationTargetException W/System.err( 7029): at java.lang.reflect.Method.invokeNative(Native Method) W/System.err( 7029): at java.lang.reflect.Method.invoke(Method.java:515) W/System.err( 7029): at acidhax.cordova.chromecast.Chromecast.execute(Chromecast.java:58) W/System.err( 7029): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65) W/System.err( 7029): at org.apache.cordova.PluginManager.execHelper(PluginManager.java:242) W/System.err( 7029): at org.apache.cordova.PluginManager.exec(PluginManager.java:227) W/System.err( 7029): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53) W/System.err( 7029): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) W/System.err( 7029): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:24) W/System.err( 7029): at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err( 7029): at android.os.Looper.loop(Looper.java:136) W/System.err( 7029): at android.os.HandlerThread.run(HandlerThread.java:61) W/System.err( 7029): Caused by: org.json.JSONException: Index 1 out of range [0..1) W/System.err( 7029): at org.json.JSONArray.get(JSONArray.java:282) W/System.err( 7029): at org.json.JSONArray.getString(JSONArray.java:451) W/System.err( 7029): at acidhax.cordova.chromecast.Chromecast.launch(Chromecast.java:130)

Definitely a step closer, but not sure what's happening here yet.

@AVGP https://github.com/AVGP , I'm not sure what the difference is. When I imported via eclipse my project.properties looked like this:

android.library.reference.1=CordovaLib

Project target.

target=android-19

Not what I would have expected. No reference here at all to the other three libraries.

— Reply to this email directly or view it on GitHub https://github.com/GetVideostream/cordova-chromecast/issues/7#issuecomment-45829119 .

JudeOsborn commented 10 years ago

Actually, never mind my last comment (sort of). I was looking at the wrong project. The libraries are indeed loading (and the sorcery is still there) but I'm not getting that error message. Looks like it's working better now. Not quite connecting to the Chromecast, but I feel like I'm getting close.

marques99 commented 10 years ago

You cannot just add the Jar files, you will need to import them as libraries with resources. http://developer.android.com/tools/support-library/setup.html#libs-with-res

JudeOsborn commented 10 years ago

@marques99 , we're aware that the jars won't work. The problem is that we've been trying to import the project libraries (the entire folders) using the command line, but have had no success. It has only worked when importing them in Eclipse.

Either way, I noticed the "refactor" branch does a pretty job of importing the dependencies as plug-ins rather than relying on manual import. Hopefully this will happen with master as well.

AVGP commented 10 years ago

Yup. We got that from the Google-fu. And that's what we did, as can be seen in the project.properties I posted. No workee. New ideas, please? Am 12.06.2014 06:38 schrieb "marques99" notifications@github.com:

You cannot just add the Jar files, you will need to import them as libraries with resources. http://developer.android.com/tools/support-library/setup.html#libs-with-res

— Reply to this email directly or view it on GitHub https://github.com/GetVideostream/cordova-chromecast/issues/7#issuecomment-45829436 .

JudeOsborn commented 10 years ago

Sorry, I deleted my previous post because I had made mistake, but in summary, after importing via eclipse, my project.properties looked like this:

android.library.reference.1=CordovaLib
# Project target.
target=android-19

As @AVGP pointed out toward the beginning of this post, we would have expected each of the three libraries to be referenced here, but that's not the case. Black magic, I say!

grahamkennery commented 10 years ago

Alright - so I had some time today to try setting up a fresh cordova project... and yeah... I cannot get the app to run correctly without some Eclipse intervention. :'(

Once I get it running with Eclipse - the command-line cordova works fine.

The steps I had to take that aren't documented well are the following:

  1. Add <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> to your AndroidManifest.xml
  2. Import the following library projects into Eclipse from your Android SDK: android-support-v7-appcompat, android-support-v7-mediarouter, google-play-services_lib
  3. Make sure that appcompat is added as a library project for the mediarouter project
  4. Add ALL THREE of those imported projects as Library projects to your cordova application.

I also had some issues after doing this correctly - the way that I fixed those problems is by cleaning the workspace and building each library project one by one manually and finishing by building and debugging the cordova app.

kataklisma commented 10 years ago

hello nothing of what I ltto helped me titanic undertaking. I was not able to solve it by adding the plugin to mediarouter, appcomat, google-play-services. support-v4, and even with the manual procedure done both manually and with the sublime with both eclipse.

the error I get is always the initial one,

java.lang.NoClassDefFoundError: android.support.v7.mediarouter.R $ string 

I tried with both branches (master and refactor).

I also had to slightly modify some java classes to refactor because it gave error in multiple catch.

you could write a complete procedure for the import of libraries and the use of basic chromecast?

pkaul commented 10 years ago

@grahamkennery:

I have managed it to perform the mentioned steps without using eclipse. This is what I did

Still pretty complicated but it works for me.

JudeOsborn commented 10 years ago

I followed your instructions to the T and it's working for me now without eclipse. I think it must be the ant clean and ant release that I wasn't doing before. Thank you very much!

renandecarlo commented 10 years ago

I did what @pkaul suggested and it worked. However, I was getting an error upon choosing my chromecast on the list, saying that a com.google.android.gms.version meta-data tag was needed in the AndroidManifest.xml file. So I did what @grahamkennery suggested on step 1 and I got it working.

The file is in the platforms/android/ directory, and the tag must be inside the <application> tag.