Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin doesn't work on Android #432

Closed
zelphir opened this issue Apr 3, 2014 · 32 comments
Closed

Plugin doesn't work on Android #432

zelphir opened this issue Apr 3, 2014 · 32 comments

Comments

@zelphir
Copy link

zelphir commented Apr 3, 2014

Using cordova 3.4.0-0.1.3, Android 4.4.2.

On iOS it is perfect, no problems, not able to make it working on android, I always get an error:

[ERROR] Error initialising Cordova: Class not found

screen shot 2014-04-03 at 15 57 53

@confile
Copy link

confile commented Apr 5, 2014

I you use cordova make sure you have the following import:

        <!-- cordova -->
        <script src="cordova.js"></script>
        <!-- cordova facebook plugin -->
        <script src="cdv-plugin-fb-connect.js"></script>
        <!-- facebook js sdk -->
        <script src="facebook-js-sdk.js"></script>

@blaind
Copy link
Contributor

blaind commented Apr 6, 2014

I'm having the same problem. Using the above mentioned imports did not help. Somehow it seems that the Facebook plugin crashes the android-side of cordova libraries; e.g. javascript files are there, but none of their functionality actually works. Build succeeds fine, and I see that cordovalib files are included in there.

@confile
Copy link

confile commented Apr 6, 2014

You also have to edit your res/xml/config.xml with the following line:


<feature name="org.apache.cordova.facebook.Connect">
         <param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
     </feature>

@confile
Copy link

confile commented Apr 6, 2014

@blaind Does cordova build works in your case? It did not work for me.

@blaind
Copy link
Contributor

blaind commented Apr 6, 2014

@confile Yes, cordova (well, phonegap, but tried both if it matters) build works: http://pastebin.com/L9GstYGJ and diff to a build without facebook plugin: http://pastebin.com/7rRY0AwV

config.xml looks like this (from plugin add)

    <feature name="FacebookConnectPlugin">
        <param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
    </feature>

@confile
Copy link

confile commented Apr 6, 2014

Change

    <feature name="FacebookConnectPlugin">
        <param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
    </feature>

to


<feature name="org.apache.cordova.facebook.Connect">
         <param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
     </feature>

@blaind I could not get build to work with facebook plugin. Here are the steps I did


cordova create Test com.example "Test"
cordova platform add android
cordova -d plugin add /Users/mg/Documents/Android/Plugins/phonegap-facebook-plugin --variable APP_ID="123456543454354" --variable APP_NAME="testtest"

The I open ADT, create new Project > Android from existing source > select two two projects in Test/platforms/android.

Right click on Test in ADT. Android > Add Facebook SDK.

The in console I did cordova build and get the following error:

BUILD FAILED
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:601: The following error occurred while executing this line:
/Users/mg/Documents/Android/Plugins/facebook-android-sdk-3.8.0/facebook/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var

Total time: 0 seconds
Error code 1 for command: ant with args: debug,-f,/Users/mg/Documents/Android/Test/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/mg/Documents/Android/Test/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:112:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

Do you have any idea how to solve it? What do you do to make it work?

@blaind
Copy link
Contributor

blaind commented Apr 6, 2014

I did this to fix the sdk.dir problem:

$ cp platforms/android/local.properties platforms/android/FacebookLib

also, for manually adding the FacebookLib (you don't need to do this if you did it already in eclipse)

$ echo "android.library.reference.2=FacebookLib" >> platforms/android/project.properties

@confile
Copy link

confile commented Apr 6, 2014

@blaind Which Facebook SDK do you use? I use facebook-android-sdk-3.8.0

@confile
Copy link

confile commented Apr 6, 2014

@blaind I did

cp platforms/android/local.properties platforms/android/FacebookLib
echo "android.library.reference.2=FacebookLib" >> platforms/android/project.properties

and now I get the following error when doing cordova build:

BUILD FAILED
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:653: The following error occurred while executing this line:
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:698: null returned: 1

Total time: 1 second
Error code 1 for command: ant with args: debug,-f,/Users/mg/Documents/Android/Test/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/mg/Documents/Android/Test/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:112:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

Do you have any idea on that?

@sebastianzillessen
Copy link
Contributor

👍 the android installation is not working for me at all. I tried several different steps and the result is either that I get the errors described above during building process OR i get the Application error (initial comment in this post).

Please, has anyone an idea?
Thanks!

@blaind
Copy link
Contributor

blaind commented Apr 7, 2014

@confile You may have the FacebookLib reference now two times in platforms/android/project.properties

@sebastianzillessen I may have found the root cause for this. Does your plugins/android.json contain both "config_munge" => "config.xml" (with facebook stuff) and "config_munge" => "res/xml/config.xml" (other module -definitions) sections? Try merging them to res/xml/config.xml. That helped for me.

@zelphir
Copy link
Author

zelphir commented Apr 7, 2014

I was able to make it working...

These are my steps:

  • Install FB plugin

    cordova -d plugin add https://phonegap-facebook_repo --variable APP_ID="*APPID*" --variable APP_NAME="*APPNAME*"
    

    Unfortunately it works only with this repo and not with the official one, just because the FB SDK is updated to latest version link

  • Add the FacebookLib to the Android project

    echo "android.library.reference.2=FacebookLib" >> platforms/android/project.properties
    
  • if you get an error while building android app (sdk.dir error) do that:

    cp platforms/android/local.properties platforms/android/FacebookLib
    
  • Remember to check the FB android app hash!

@confile
Copy link

confile commented Apr 8, 2014

@zelphir Did you mean this repo: https://github.com/keab42/phonegap-facebook-plugin

I did

cordova -d plugin add https://github.com/keab42/phonegap-facebook-plugin --variable APP_ID="1234567" --variable APP_NAME="testtest"

After that I do not have a FacebookLib in my lib directory. So I added the FacebookSDK manually in ADT.

When I do crdova build I get the following error:

BUILD FAILED
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:653: The following error occurred while executing this line:
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:698: null returned: 1

Total time: 1 second
Error code 1 for command: ant with args: debug,-f,/Users/mg/Documents/Android/Test/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/mg/Documents/Android/Test/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:112:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

@Kae2312
Copy link

Kae2312 commented Apr 9, 2014

@zelphir

Hi,

Thanks for you steps but when i want to build I get the following error :

BUILD FAILED
build.xml:460: FacebookLib resolve to a path with no project.properties file for project /Users/guillaume/Desktop/huhu/huhu/platforms/android

Total time: 0 seconds

Is it already happened to someone?

@himangshuj
Copy link

@Kae2312 the same error is happening to me

@fpanettieri
Copy link

I've just managed to fix this same issue.

First create a project (or use a existing one) and add th android platform

cordova create Test com.example "Test"
cordova platform add android

Then you have to install the plugin

 cordova -d plugin add "C:\Development\phonegap-facebook-plugin-master" --variable APP_ID="xxxxxxxxxxxxxxx" --variable APP_NAME="xxxxxxxxxx"

After manually adding the library using eclipse as the README explains, and cleaning the project, close eclipse. It might complain about the path, don't worry it's fine.

Here was the main issue, if you tried to compile the project now using "cordova build android" it will fail with mysterious and unrelated error messages.

You might find a couple of issues, the first related to a "sdk.dir".

What you have to do to solve that is, open plaforms/android/project.properties.
Copy the variable (in my case it looks like this sdk.dir=C:\Development\adt-bundle\sdk) to platfoms/android/FacebookLib/project.properties

Then, make sure the sdk min version is 8 on your application AndroidManifest.xml

And finally you have to manually clean the project that eclipse attempted to build.

cd platforms/android
ant clean
cd ../../
cordova build android

And that's it, those instructions did the trick for me. I spent some time solving this, hope it helps!

@jtomaszewski
Copy link

Thank you @fpanettieri ! ant clean fixed my problems with ant/build.xml:698: null returned: 1 error.

@rlataguerra
Copy link

@jtomaszewski it fixed my problem too, eclipse is really adding extra trouble in that story.
Thank you to @fpanettieri for that.

Maybe the readme should contain the steps without eclipse, just in cli

Edit: app crash when calling the .login method

E/AndroidRuntime(32685): FATAL EXCEPTION: main
E/AndroidRuntime(32685): Process: com.ionicframework.starter, PID: 32685
E/AndroidRuntime(32685): java.lang.NoClassDefFoundError: com.facebook.android.R$layout

@fpanettieri
Copy link

There is one more thing that I discovered, that might be useful for you to know.

I've downloaded and built the Facebook 3.14 SDK, and replaced the FacebookLib reference with the reference to that project. It's a drop-in replacement, it works as expected, with a newer version than the included in current the plugin (3.8 if I recall correctly).

There is another catch. When ant attempts to build this dependence, It will fail if you don't remove the folder (at least in Windows): C:\path\to...\facebook-android-sdk-3.14\facebook\bin\res

@rlataguerra
Copy link

Just to tell people know, it finally worked. I just needed to build it with Eclipse (I was doing a cli build)

@nathvarun
Copy link

@fpanettieri Copying the sdk.dir works! thanks

@joaoneto
Copy link

joaoneto commented Jun 1, 2014

when Eclipse build, FB.login() works fine...
when cordova build's, and when fires FB.login(), I have this stack trace with adb shell logcat:

D/CordovaActivity(18599): Paused the application!
D/CordovaWebView(18599): Handle the pause
W/PluginManager(18599): THREAD WARNING: exec() call to FacebookConnectPlugin.login blocked the main thread for 304ms. Plugin should use CordovaInterface.getThreadPool().
D/AndroidRuntime(18599): Shutting down VM
W/dalvikvm(18599): threadid=1: thread exiting with uncaught exception (group=0x416a7d40)
E/AndroidRuntime(18599): FATAL EXCEPTION: main
E/AndroidRuntime(18599): Process: com.example.labs, PID: 18599
E/AndroidRuntime(18599): java.lang.NoClassDefFoundError: com.facebook.android.R$layout
E/AndroidRuntime(18599):    at com.facebook.LoginActivity.onCreate(LoginActivity.java:57)
E/AndroidRuntime(18599):    at android.app.Activity.performCreate(Activity.java:5248)
E/AndroidRuntime(18599):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
E/AndroidRuntime(18599):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
E/AndroidRuntime(18599):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
E/AndroidRuntime(18599):    at android.app.ActivityThread.access$800(ActivityThread.java:139)
E/AndroidRuntime(18599):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
E/AndroidRuntime(18599):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(18599):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(18599):    at android.app.ActivityThread.main(ActivityThread.java:5102)
E/AndroidRuntime(18599):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(18599):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(18599):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime(18599):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime(18599):    at dalvik.system.NativeStart.main(Native Method)

UPDATE
Sorry, my bad...
Works running follow:
$ ./platforms/android/cordova/clean
$ cordova prepare android
$ cordova run --debug android

@aogilvie
Copy link
Collaborator

Closing, initial issue has been resolved.

@levsa
Copy link
Contributor

levsa commented Jun 17, 2014

I have the same problem:
java.lang.NoClassDefFoundError: com.facebook.android.R$layout

I've tried cordova/clean, cordova prepare android and cordova build android, but it didn't help. When I list the classes in FacebookLib/ant-build/classes.jar, there is no R$layout.class, although it exists in the ant-gen directory.

@levsa
Copy link
Contributor

levsa commented Jun 17, 2014

The reason for the problem is that the android ant scripts exclude R-classes from the library jar file. I can't see why and how the R-files for the facebook lib is supposed to end up in the final apk when using ant (or cordova) build.

Manually copying FacebookLib/ant-gen/com to ant-gen/ seems to help.

@pifantastic
Copy link

@levsa any luck with the NoClassDefFoundError? Is copying the FacebookLib/ant-gen/com to ant-gen/ the best solution? I'm struggling with this issue as well.

@levsa
Copy link
Contributor

levsa commented Jun 23, 2014

Copying didn't work, got nullpointerexceptions at runtime. Building with
eclipse worked though.

måndag 23 juni 2014 skrev Aaron Forsander notifications@github.com:

@levsa https://github.com/levsa any luck with the NoClassDefFoundError?
Is copying the FacebookLib/ant-gen/com to ant-gen/ the best solution? I'm
struggling with this issue as well.


Reply to this email directly or view it on GitHub
#432 (comment)
.

@joaoneto
Copy link

Hi @levsa,
Another thing that also must be taken, is that we have to enter the platforms/android/FacebookLib folder and run: ant release
also platforms/android/CordovaLib

cd platforms/android/FacebookLib
ant release

cd platforms/android/CordovaLib
ant release

@mikehayesuk
Copy link
Contributor

I'm having the same issue as @Stickyhands , @joaoneto and others when running the app.

E/AndroidRuntime(29743): java.lang.NoClassDefFoundError: com.facebook.android.R$layout
E/AndroidRuntime(29743):    at com.facebook.LoginActivity.onCreate(LoginActivity.java:57)
E/AndroidRuntime(29743):    at android.app.Activity.performCreate(Activity.java:5426)
E/AndroidRuntime(29743):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime(29743):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
E/AndroidRuntime(29743):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
E/AndroidRuntime(29743):    at android.app.ActivityThread.access$900(ActivityThread.java:161)
E/AndroidRuntime(29743):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
E/AndroidRuntime(29743):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(29743):    at android.os.Looper.loop(Looper.java:157)
E/AndroidRuntime(29743):    at android.app.ActivityThread.main(ActivityThread.java:5356)
E/AndroidRuntime(29743):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(29743):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(29743):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
E/AndroidRuntime(29743):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
E/AndroidRuntime(29743):    at dalvik.system.NativeStart.main(Native Method)

Building with Eclipse does not seem like a "real" solution, especially considering that this is not mentioned in the README. There has to be a cleaner way of integrating a Cordova app with the Facebook SDK. For now, I'm giving up. May look at using our existing online FB oauth login + InAppBrowser, not ideal but the native SDK plugin is taking up a lot of time and I'm already behind schedule on this particular project.

Would love to hear if anyone had any thoughts on the future of Cordova + phonegap-facebook-plugin and this issue :-)

@kaansoral
Copy link

Best course of action: drop fb integration, it's getting too complicated lately and the gain is getting lower and lower, without cordova in the equation

Simple solution: Download ADT, apply the steps, search for this issue tracker to solve the problems

ADT process is extremely simple, once you get the hang of it

It's really easy to re-apply

You can both update the project, or the FacebookSDK and easily re-apply the steps

You just have to clean the project you have edited on ADT/Eclipse

@ajbraus
Copy link

ajbraus commented Jul 8, 2014

its your plugins

solution is rm android platform
npm cordova in the root of your project
then add android platform back and reinstall all plugins

http://forum.ionicframework.com/t/erroe-error-initializing-cordova-class-not-found-only-on-android/3555/8

@francoro
Copy link

Use this https://github.com/jeduan/cordova-plugin-facebook4 it has all the android sdk problems solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests