Bug 12195 - Can not add a class named Com.Facebook.LoginActivity in an android project namespace com.myproject when a binding lib called Com.Facebook is also referenced
Summary: Can not add a class named Com.Facebook.LoginActivity in an android project na...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.7.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-05-10 11:12 UTC by softlion
Modified: 2013-06-22 06:24 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description softlion 2013-05-10 11:12:19 UTC
The native android facebook binding lib requires an activity in the main android app. This activity must be named com.facebook.LoginActivity. This activity is launched by the facebook lib when returning the control from the facebook android app to my app. 

adb logcat trace:
E/AndroidRuntime(30566): java.lang.RuntimeException: Failure delivering result 
ResultInfo{who=null, request=64206, result=0, data=null} 
to activity {com.myapp.droid/com.facebook.LoginActivity}: 

If i add a class like this in the myapp project, then the project won't link with error MSB6006: "java" exited with code 1 in C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1025,3).

namespace Com.Facebook
    [Activity(Theme = "@android:style/Theme.Holo.Light.Dialog", ExcludeFromRecents = true, Label = "Returned from Facebook")]
    public class LoginActivity : Activity
        protected override void OnCreate(Bundle bundle)
Comment 1 Jonathan Pryor 2013-05-13 16:58:46 UTC
Can you please provide Diagnostic build output?


The `javac` error messages should be displayed in Diagnostic output, which will narrow down what the problem is.

I'm able to add your specified Com.Facebook.LoginActivity type to a new project without any error.
Comment 2 softlion 2013-05-13 17:14:46 UTC
Ah i was searching for detailed diagnostics ...
So the error is exactly what i was thinking about.
It seems this class already exists in the facebook binding lib, in the same namespace, but not in the same package. And this is not supported by monodroid :(

In monodroid project:

namespace com.facebook
    [Activity(Theme = "@android:style/Theme.Holo.Light.Dialog", ExcludeFromRecents = true, Label = "Ouverture de Facebook")]
    public class LoginActivity : Activity
        protected override void OnCreate(Bundle bundle)

Binding lib:

2>  java.lang.IllegalArgumentException: already added: Lcom/facebook/LoginActivity; (TaskId:250)
2>  	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) (TaskId:250)
2>  	at com.android.dx.dex.file.DexFile.add(DexFile.java:163) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.processClass(Main.java:490) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.access$400(Main.java:67) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398) (TaskId:250)
2>  	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245) (TaskId:250)
2>  	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131) (TaskId:250)
2>  	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.processOne(Main.java:422) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.run(Main.java:209) (TaskId:250)
2>  	at com.android.dx.command.dexer.Main.main(Main.java:174) (TaskId:250)
2>  	at com.android.dx.command.Main.main(Main.java:91) (TaskId:250)
2>  1 error; aborting (TaskId:250)
Comment 4 softlion 2013-05-13 17:23:53 UTC
See https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

And specifically the sentence "Finally, add a new Activity to the app, with the name com.facebook.LoginActivity"
Comment 5 softlion 2013-05-13 17:26:32 UTC
I've runned adb logtrace when the android facebook app tries to return to my app. It tries to start an activity called "com.facebook.LoginActivity" in my package. The activity is not found, and android "crashes" ... not facebook but my app !
Comment 6 softlion 2013-05-13 17:27:25 UTC
This happens only if you are not logged in the facebook android app when you click the facebook connect button in my app.
Comment 7 softlion 2013-05-13 17:34:49 UTC
And in facebook you click the "back" button without logging in :)

Currently i've manually added an activity tag in the manifest file. This activity tag does not have a matching class. That is why in the following trace the process is crashing.

But the trace shows how facebook uses this activity to "return" to my app.
I know the facebook lib is doing funny things...

adb trace:

W/ActivityManager(  577): Duplicate finish request for ActivityRecord{42dd6c48 c
W/dalvikvm( 3854): threadid=1: thread exiting with uncaught exception (group=0x4
E/AndroidRuntime( 3854): FATAL EXCEPTION: main
E/AndroidRuntime( 3854): java.lang.RuntimeException: Failure delivering result R
esultInfo{who=null, request=64206, result=0, data=null} to activity {com.stickan
dtag.droid/com.facebook.LoginActivity}: java.lang.NullPointerException
E/AndroidRuntime( 3854):        at android.app.ActivityThread.deliverResults(Act
E/AndroidRuntime( 3854):        at android.app.ActivityThread.handleSendResult(A
E/AndroidRuntime( 3854):        at android.app.ActivityThread.access$1100(Activi
E/AndroidRuntime( 3854):        at android.app.ActivityThread$H.handleMessage(Ac
E/AndroidRuntime( 3854):        at android.os.Handler.dispatchMessage(Handler.ja
E/AndroidRuntime( 3854):        at android.os.Looper.loop(Looper.java:213)
E/AndroidRuntime( 3854):        at android.app.ActivityThread.main(ActivityThrea
E/AndroidRuntime( 3854):        at java.lang.reflect.Method.invokeNative(Native
E/AndroidRuntime( 3854):        at java.lang.reflect.Method.invoke(Method.java:5
E/AndroidRuntime( 3854):        at com.android.internal.os.ZygoteInit$MethodAndA
E/AndroidRuntime( 3854):        at com.android.internal.os.ZygoteInit.main(Zygot
E/AndroidRuntime( 3854):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime( 3854): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3854):        at com.facebook.AuthorizationClient$KatanaProxyA
E/AndroidRuntime( 3854):        at com.facebook.AuthorizationClient.onActivityRe
E/AndroidRuntime( 3854):        at com.facebook.LoginActivity.onActivityResult(L
E/AndroidRuntime( 3854):        at android.app.Activity.dispatchActivityResult(A
E/AndroidRuntime( 3854):        at android.app.ActivityThread.deliverResults(Act
E/AndroidRuntime( 3854):        ... 11 more
W/ActivityManager(  577):   Force finishing activity com.stickandtag.droid/com.f
Comment 8 Atsushi Eno 2013-05-22 16:21:50 UTC
Note that our facebook binding is just a "sample", not any sort of "feature" that we support. You rather seem to have added a class LoginActivity in the same package (com.facebook) while the latest Facebook library contains one in the Java library itself.

> The native android facebook binding lib requires an activity in the main
android app. This activity must be named com.facebook.LoginActivity. 

I'm not sure where you got this requirement. Isn't it true only to old versions of Facebook SDK? Since there is com.facebook.LoginActivity in the latest SDK, it sounds like you are not supposed to add it by yourself.

If that's not what you meant or what you expected, please provide the actual reproducible project that explains the facts more than your words. Thanks.
Comment 9 softlion 2013-05-22 17:45:12 UTC
I don't use your facebook binding, i created my own.

> I'm not sure where you got this requirement.


Search for the sentence "Finally, add a new Activity to the app, with the
name com.facebook.LoginActivity"

SDK v3 is still the latest.

I will post a sample repro project shortly.
Comment 10 Atsushi Eno 2013-06-21 08:19:30 UTC
Recently I have created a refresh binding for Facebook Android SDK that targets version 3.0.1. Since it depends on our alpha version (4.7.x) we cannot push this in our monodroid-samples/Facebook yet, but I can share the entire project:

I also put it on nuget.org so you can easily use it via nuget package manager (in VS, and XS if you install the NuGet addin by community): https://nuget.org/packages/Xamarin.FacebookBinding/

My wild guess on the error you got earlier is, you have some C# code like:

namespace com.facebook.android {
    public class LoginActivity : Activity {

which results in its own ACW (Android Callable Wrapper, Java class which comes from the C# class) which has the identical name as Facebook Android SDK already contains, and results in that error. Basically you didn't need to add it by yourself or you are supposed to manually "register" it, disabling ACW generation.

But as long as you use the latest 4.7.x and the package above, you won't need to do that now :)

(Hence I mark this as RESOLVED as FEATURE.)
Comment 11 softlion 2013-06-22 03:54:39 UTC
You are right.

It works perfectly with your binding.
I'd love to know to write those.

You still need a line like this though, otherwise the lib won't let you open a fb session:
    <activity-alias android:name="com.facebook.LoginActivity" android:targetActivity="tagzi.droid.ui.activities.RegisterSelectMethodActivity" />

The ShowSearchBox property is still missing on PlacePickerFragment ?
Is your binding using fb sdk 3.0.1 ?

Thank you you enlightened my WE with your nuget package.
Comment 12 softlion 2013-06-22 06:24:53 UTC
Sory my previous post : it does not work.
To make it work you must add a "fake" activity with no code associated.
It compiles ok.

<activity android:name="com.facebook.LoginActivity" />

That's what i was already doing in my previous version.
That flashes a white activity then dislays the faceook auth dialogs. That's a cosmetic problem but i don't know how to avoid it.

using a real activity or an activity-alias leads to the activity being launched, and no fb dialog appears.