8

I have used maven-android-plugin 3.0.0-alpha-7 to package the facebook android sdk as a apklib. It looks like this:

    $ unzip sdk-1.0-SNAPSHOT.apklib
    Archive:  sdk-1.0-SNAPSHOT.apklib
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    
  inflating: AndroidManifest.xml     
   creating: assets/
   creating: res/
   creating: res/drawable/
   creating: res/drawable-hdpi/
   creating: res/drawable-ldpi/
  inflating: res/drawable/facebook_icon.png  
  inflating: res/drawable-hdpi/facebook_icon.png  
  inflating: res/drawable-ldpi/facebook_icon.png  
   creating: src/
   creating: src/com/
   creating: src/com/facebook/
   creating: src/com/facebook/android/
  inflating: src/com/facebook/android/AsyncFacebookRunner.java  
  inflating: src/com/facebook/android/DialogError.java  
  inflating: src/com/facebook/android/Facebook.java  
  inflating: src/com/facebook/android/FacebookError.java  
  inflating: src/com/facebook/android/FbDialog.java  
  inflating: src/com/facebook/android/Util.java  

I then install it into a local repo for my project and include it as a maven dep... and run the build I get this:

$ mvn clean package android:deploy
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ myproject-android ---
[INFO] Deleting /Users/user/dev/projects/company/myproject-android/target
[INFO] 
[INFO] --- maven-android-plugin:3.0.0-alpha-7:generate-sources (default-generate-sources) @ myproject-android ---
[DEBUG] Expanding: /Users/user/.m2/repository/com/facebook/android/sdk/1.0-SNAPSHOT/sdk-1.0-SNAPSHOT.apklib into /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT
[DEBUG] expand complete
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] /Users/user/dev/libs/android-sdk-mac_x86/platform-tools/aapt [package, -m, -J, /Users/user/dev/projects/company/myproject-android/target/generated-sources/r, -M, /Users/user/dev/projects/company/myproject-android/AndroidManifest.xml, -S, /Users/user/dev/projects/company/myproject-android/res, -S, /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT/res, --auto-add-overlay, -A, /Users/user/dev/projects/company/myproject-android/assets, -I, /Users/user/dev/libs/android-sdk-mac_x86/platforms/android-10/android.jar]
[INFO] /Users/user/dev/libs/android-sdk-mac_x86/platform-tools/aapt [package, -m, -J, /Users/user/dev/projects/company/myproject-android/target/generated-sources/r, --custom-package, com.facebook, -M, /Users/user/dev/projects/company/myproject-android/AndroidManifest.xml, -S, /Users/user/dev/projects/company/myproject-android/res, -S, /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT/res, --auto-add-overlay, -A, /Users/user/dev/projects/company/myproject-android/assets, -A, /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT/assets, -I, /Users/user/dev/libs/android-sdk-mac_x86/platforms/android-10/android.jar]
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myproject-android ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/user/dev/projects/company/myproject-android/src/main/resources
[INFO] skip non existing resourceDirectory /Users/user/dev/projects/company/myproject-android/target/generated-sources/extracted-dependencies/src/main/resources
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myproject-android ---
[INFO] Compiling 141 source files to /Users/user/dev/projects/company/myproject-android/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT/src/com/facebook/android/FbDialog.java:[95,17] package R does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Skipping myproject
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.279s
[INFO] Finished at: Wed Sep 21 09:32:40 PDT 2011
[INFO] Final Memory: 13M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project myproject-android: Compilation failure
[ERROR] /Users/user/dev/projects/company/myproject-android/target/unpack/apklibs/com.facebook.android_sdk_apklib_1.0-SNAPSHOT/src/com/facebook/android/FbDialog.java:[95,17] package R does not exist
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I see the R files are getting generated and have the correct contents:

$ find target/generated-sources/r/
target/generated-sources/r/
target/generated-sources/r//com
target/generated-sources/r//com/facebook
target/generated-sources/r//com/facebook/Manifest.java
target/generated-sources/r//com/facebook/R.java
target/generated-sources/r//com/company
target/generated-sources/r//com/company/myproject
target/generated-sources/r//com/company/myproject/droid
target/generated-sources/r//com/company/myproject/droid/Manifest.java
target/generated-sources/r//com/company/myproject/droid/R.java

What am I missing to get the R files included in the compilation step?

j0k
  • 22,600
  • 28
  • 79
  • 90
danb
  • 10,239
  • 14
  • 60
  • 76

1 Answers1

13

I already did that for you: https://github.com/casidiablo/android-facebook

Download

Latest version available is 1.5:

Maven

You can use it from Maven by including this dependency and repository:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>com.codeslap</groupId>
            <artifactId>android-facebook</artifactId>
            <version>1.6</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>codeslap</id>
            <url>http://casidiablo.github.com/codeslap-maven/repository/</url>
        </repository>
    </repositories>
</project>
Community
  • 1
  • 1
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • I did it that way too at first. but it doesn't seem to address the facebook_icon.png resource and the creation/merge of the R.java file with our project's R.java file. As far as I can tell, to have the resources play nice with our project we have to package the facebook stuff as an apklib so the source files and resources are available at source generation time in our project. or am I missing something? – danb Sep 21 '11 at 16:55
  • 2
    Yes, I solve that problem by creating a Base64 icon. Take a look at the source code of my facebook version. – Cristian Sep 21 '11 at 18:09
  • Ok, cool, I'll give it a shot. How frequently do you merge with the current code line from facebook? – danb Sep 21 '11 at 18:12
  • This works great. I would still like to package an apklib from source and have it play nice in my build process, but I need to move on today, and this package gets the job done with no hassle. Thanks! – danb Sep 21 '11 at 18:27
  • Just a caveat: base64 is kind of big. It looks cool on HDPI screens. One task I want to do later is add two more icons: for MDPI and LDPI. Problem is that when you see icon in LDPI screen, it looks really big. – Cristian Sep 21 '11 at 18:29
  • I see there have been some updates to the facebook sdk, but the version number for your package hasn't changed, does that mean you haven't merged yet? – danb Nov 14 '11 at 22:24
  • 1
    It means I have too much work XD I will take a look at that soon; thanks for letting me know. – Cristian Nov 15 '11 at 04:15
  • This repo seems to go down for days at a time and really stalls out our builds. I would contribute some money if the hosting could be moved to S3... – danb Jan 26 '12 at 18:26
  • 1
    Hey danb, give me a couple of days. I am moving that repository to another server. The current one is shitty as hell. Please be patience. And do not worry about money. Thanks for your interest :) – Cristian Jan 26 '12 at 19:23
  • @danb hey dude! Just move the project to Github. It will now be much more stable. Also, I updated the library to the latest version. – Cristian Jan 30 '12 at 20:22
  • so we should be switched over to the codeslap namespace on github now? http://casidiablo.github.com/codeslap-maven/repository/ – danb Feb 06 '12 at 20:12
  • Yes please. I had some legal problems with the other name :) – Cristian Feb 07 '12 at 04:32
  • Any chance we can get a new version for this security hole ASAP? http://techcrunch.com/2012/04/10/security-hole-spotted-in-facebook-android-sdk-long-tail-apps-may-still-be-unpatched/ – emmby Apr 10 '12 at 23:51
  • @emmby that bug does not affect this library because it is compiled with the debug flag disabled; it means it does not print any information to the log thus no token is revealed. – Cristian Apr 11 '12 at 04:26
  • @Cristian looks like it's been a while since a merge. are you still maintaining this? – danb Oct 22 '12 at 17:10
  • I have no much time lately... you can clone and merge it your self and send a pull request if you want. Thank you so much. – Cristian Oct 22 '12 at 17:32
  • Downvoting because the SDK is significantly out of date now and in many ways no longer works due to offline access deprecation: developers.facebook.com/docs/offline-access-deprecation – emmby Jan 11 '13 at 00:04
  • Project is open source... you might want to send a pull request. I'd be happy to merge it. – Cristian Jan 12 '13 at 06:45