Facebook v4 Compilation Error

Hi guys,

My project is able to compile if I don’t add facebook. I get the apk file and able to use it on a device.

I have been following the tutorial at https://docs.coronalabs.com/daily/plugin/facebook-v4/index.html and also sent the command ‘android update project  --path /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/’

I get the compilation error below when I "./build.sh $ANDROID_HOME

-pre-compile: -compile: [javac] Compiling 154 source files to /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/bin/classes [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/AccessToken.java:559: illegal start of type [javac] ArrayList\<String\> permissionsList = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/AccessTokenManager.java:224: illegal start of type [javac] final Set\<String\> permissions = new HashSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/AccessTokenManager.java:225: illegal start of type [javac] final Set\<String\> declinedPermissions = new HashSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/AttributionIdentifiers.java:255: illegal start of type [javac] private final BlockingQueue\<IBinder\> queue = new LinkedBlockingDeque\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/CallbackManagerImpl.java:37: illegal start of type [javac] private static Map\<Integer, Callback\> staticCallbacks = new HashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/CallbackManagerImpl.java:71: illegal start of type [javac] private Map\<Integer, Callback\> callbacks = new HashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/CollectionMapper.java:63: illegal start of type [javac] List\<T\> keys = new LinkedList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/FacebookRequestErrorClassification.java:169: illegal start of type [javac] Map\<Integer, Set\<Integer\>\> items = new HashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/FacebookRequestErrorClassification.java:182: illegal start of type [javac] subcodes = new HashSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/NativeAppCallAttachmentStore.java:112: illegal start of type [javac] List\<File\> filesToCleanup = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/NativeProtocol.java:772: illegal start of type [javac] TreeSet\<Integer\> allAvailableVersions = new TreeSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/ProfileInformationCache.java:37: illegal start of type [javac] new ConcurrentHashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/Utility.java:961: illegal start of type [javac] ArrayList\<String\> result = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/Utility.java:971: illegal start of type [javac] Set\<String\> result = new HashSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/internal/Utility.java:1243: illegal start of type [javac] Map\<String, String\> map = new HashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/login/LoginClient.java:493: illegal start of type [javac] ArrayList\<String\> permissionsList = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/login/LoginManager.java:356: illegal start of type [javac] this.pendingLoggingExtras = new HashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/LegacyNativeDialogParameters.java:106: illegal start of type [javac] params.putStringArrayList(ShareConstants.LEGACY\_PHOTOS, new ArrayList\<\>(imageUrls)); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/LegacyNativeDialogParameters.java:152: illegal start of type [javac] new ArrayList\<\>(peopleIds)); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/LikeActionController.java:117: illegal start of type [javac] new ConcurrentHashMap\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/LikeDialog.java:101: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/NativeDialogParameters.java:109: illegal start of type [javac] params.putStringArrayList(ShareConstants.PHOTOS, new ArrayList\<\>(imageUrls)); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:305: illegal start of type [javac] ArrayList\<NativeAppCallAttachmentStore.Attachment\> attachments = new ArrayList\<\>(1); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:317: illegal start of type [javac] final ArrayList\<NativeAppCallAttachmentStore.Attachment\> attachments = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:368: illegal start of type [javac] actionJSON.put("tags", new ArrayList\<\>(peopleIdSet)); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:475: illegal start of type [javac] return new Pair\<\>(namespace, fieldName); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:605: illegal start of type [javac] new GraphRequest.ParcelableResourceWithMimeType\<\>(descriptor, "image/png"); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/ShareInternalUtility.java:645: illegal start of type [javac] new GraphRequest.ParcelableResourceWithMimeType\<\>(imageUri, "image/png"); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/internal/VideoUploader.java:96: illegal start of type [javac] private static Set\<UploadContext\> pendingUploads = new HashSet\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/model/GameRequestContent.java:71: illegal start of type [javac] this.suggestions = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/model/SharePhoto.java:206: illegal start of type [javac] final List\<SharePhoto\> list = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/model/SharePhoto.java:214: illegal start of type [javac] final List\<SharePhoto\> list = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/AppInviteDialog.java:179: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/CreateAppGroupDialog.java:156: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/GameRequestDialog.java:176: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/JoinAppGroupDialog.java:155: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/MessageDialog.java:155: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/src/com/facebook/share/widget/ShareDialog.java:223: illegal start of type [javac] ArrayList\<ModeHandler\> handlers = new ArrayList\<\>(); [javac] ^ [javac] 38 errors BUILD FAILED /Users/XXX/Library/Android/sdk/tools/ant/build.xml:597: The following error occurred while executing this line: /Users/XXX/Library/Android/sdk/tools/ant/build.xml:716: The following error occurred while executing this line: /Users/XXX/Library/Android/sdk/tools/ant/build.xml:730: Compile failed; see the compiler error output for details.

Any ideas ?

Thanks

Ah. It looks like it’s failing on all the Diamond operators. These were introduced in Java 7 and thus, you’ll need to download a Java 7 JDK to compile the Facebook SDK source yourself.

Dear Ajay, Thanks for the info. I followed the Enterprise setup guide here (https://docs.coronalabs.com/native/android/prereqs.html) and it uses Java 6. I am using the Facebook sdk 4.5.0 (provided in the Enterprise zip file). Does this mean the other Enterprise users are also facing the same issue, or is it just my setup ? Thanks

The guide needs updating it seems. Other users would encounter the same issue building with FB v4. You’ll need to grab Java 7 from Oracle to resolve the issue as Ajay stated.

Thanks

Thanks for the info guys.

For those encountering the same problem, here is how to solve it.

  1. Download Java 7 from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html and get ‘jdk-7u79-macosx-x64.dmg’. I am using MacAir 2014.

  2. (Optional) Read through the installation instructions here http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html

  3. After installation, it will look like this :

    Before (Java 6). Current Corona Enterprise tutorial uses Java 6 : $ java -version java version “1.6.0_65” Java™ SE Runtime Environment (build 1.6.0_65-b14-468-11M4833) Java HotSpot™ 64-Bit Server VM (build 20.65-b04-468, mixed mode) After (Java 7): $ java -version java version “1.7.0_79” Java™ SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot™ 64-Bit Server VM (build 24.79-b02, mixed mode)

.

  1. (Optional) Ensure your “android/AndroidManifest.xml” file is setup correctly, or else there will be runtime error on the device. I know it looks messy, but it should look something like that. Note only the facebook items below.

    <?xml version=“1.0” encoding=“utf-8”?> <manifest xmlns:android=“http://schemas.android.com/apk/res/android” package=“com.xxx.getWifi” android:versionCode=“1” android:versionName=“1.0” android:installLocation=“auto”> <!-- Set the minimum and target Android API levels here to inform the app store what OS versions this app supports. Set the “minSdkVersion” to at least API level 10 (aka: Android 2.3.3 “Gingerbread”) which is the minimum Corona supports. Set the “targetSdkVersion” to the API level that you compile with. Set to a high level to avoid compatibility mode. --> <uses-sdk android:minSdkVersion=“10” android:targetSdkVersion=“21”/> <!-- Permissions required by this app. --> <uses-permission android:name=“android.permission.INTERNET”/> <!-- Informs the app store that this app requires OpenGL ES 2.0 as a minimum. Required by Corona. --> <uses-feature android:glEsVersion=“0x00020000”/> <!-- Informs the app store what features are required or are optional for this app. --> <!-- Setting the telephony feature to not required allows this app to be installed by devices that are not phones. --> <!-- Provides information about this app. The “name” attribute should be set to the name of the class that extends/inherits from the Application class. The “label” attribute sets the name of the application as how it is shown to the end-user. --> <application android:name=“CoronaApplication” android:label=“getWifi” android:hardwareAccelerated=“true” android:debuggable=“true”> <meta-data android:name=“com.facebook.sdk.ApplicationId” android:value="\ XXXXXXXXXXX"/> <activity android:name=“com.facebook.FacebookActivity” android:configChanges=“keyboard|keyboardHidden|screenLayout|screenSize|orientation” android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name=“plugin.facebook.v4.FacebookFragmentActivity” android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges=“keyboardHidden|screenSize|orientation”/> <!-- The main Corona activity that runs the Corona project. --> …

  1. (Optional) If you are facing a compilation error stating “(use -source 7 or higher to enable diamond operator)”, then you will need to update the “/android/build.xml” file. Just add these 2 lines before “<import file="${sdk.dir}/tools/ant/build.xml" />

    <property name=“java.target” value=“1.7” /> <property name=“java.source” value=“1.7” /> <import file="${sdk.dir}/tools/ant/build.xml" />

Ah. It looks like it’s failing on all the Diamond operators. These were introduced in Java 7 and thus, you’ll need to download a Java 7 JDK to compile the Facebook SDK source yourself.

Dear Ajay, Thanks for the info. I followed the Enterprise setup guide here (https://docs.coronalabs.com/native/android/prereqs.html) and it uses Java 6. I am using the Facebook sdk 4.5.0 (provided in the Enterprise zip file). Does this mean the other Enterprise users are also facing the same issue, or is it just my setup ? Thanks

The guide needs updating it seems. Other users would encounter the same issue building with FB v4. You’ll need to grab Java 7 from Oracle to resolve the issue as Ajay stated.

Thanks

Thanks for the info guys.

For those encountering the same problem, here is how to solve it.

  1. Download Java 7 from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html and get ‘jdk-7u79-macosx-x64.dmg’. I am using MacAir 2014.

  2. (Optional) Read through the installation instructions here http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html

  3. After installation, it will look like this :

    Before (Java 6). Current Corona Enterprise tutorial uses Java 6 : $ java -version java version “1.6.0_65” Java™ SE Runtime Environment (build 1.6.0_65-b14-468-11M4833) Java HotSpot™ 64-Bit Server VM (build 20.65-b04-468, mixed mode) After (Java 7): $ java -version java version “1.7.0_79” Java™ SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot™ 64-Bit Server VM (build 24.79-b02, mixed mode)

.

  1. (Optional) Ensure your “android/AndroidManifest.xml” file is setup correctly, or else there will be runtime error on the device. I know it looks messy, but it should look something like that. Note only the facebook items below.

    <?xml version=“1.0” encoding=“utf-8”?> <manifest xmlns:android=“http://schemas.android.com/apk/res/android” package=“com.xxx.getWifi” android:versionCode=“1” android:versionName=“1.0” android:installLocation=“auto”> <!-- Set the minimum and target Android API levels here to inform the app store what OS versions this app supports. Set the “minSdkVersion” to at least API level 10 (aka: Android 2.3.3 “Gingerbread”) which is the minimum Corona supports. Set the “targetSdkVersion” to the API level that you compile with. Set to a high level to avoid compatibility mode. --> <uses-sdk android:minSdkVersion=“10” android:targetSdkVersion=“21”/> <!-- Permissions required by this app. --> <uses-permission android:name=“android.permission.INTERNET”/> <!-- Informs the app store that this app requires OpenGL ES 2.0 as a minimum. Required by Corona. --> <uses-feature android:glEsVersion=“0x00020000”/> <!-- Informs the app store what features are required or are optional for this app. --> <!-- Setting the telephony feature to not required allows this app to be installed by devices that are not phones. --> <!-- Provides information about this app. The “name” attribute should be set to the name of the class that extends/inherits from the Application class. The “label” attribute sets the name of the application as how it is shown to the end-user. --> <application android:name=“CoronaApplication” android:label=“getWifi” android:hardwareAccelerated=“true” android:debuggable=“true”> <meta-data android:name=“com.facebook.sdk.ApplicationId” android:value="\ XXXXXXXXXXX"/> <activity android:name=“com.facebook.FacebookActivity” android:configChanges=“keyboard|keyboardHidden|screenLayout|screenSize|orientation” android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name=“plugin.facebook.v4.FacebookFragmentActivity” android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges=“keyboardHidden|screenSize|orientation”/> <!-- The main Corona activity that runs the Corona project. --> …

  1. (Optional) If you are facing a compilation error stating “(use -source 7 or higher to enable diamond operator)”, then you will need to update the “/android/build.xml” file. Just add these 2 lines before “<import file="${sdk.dir}/tools/ant/build.xml" />

    <property name=“java.target” value=“1.7” /> <property name=“java.source” value=“1.7” /> <import file="${sdk.dir}/tools/ant/build.xml" />

what about this error when integrate facebook v4 sdk?

" [aapt] nothing matches overlay file corona_statusbar_icon_default.png, for flavor xxhdpi-v4

     [aapt] nothing matches overlay file corona_statusbar_icon_default.png, for flavor xxxhdpi-v4

     [aapt] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/res/layout/picker_title_bar.xml:44: error: No resource identifier found for attribute ‘layout_alignStart’ in package ‘android’

     [aapt] "

Hi mlhdyx,

In your AndroidManifest.xml, what is the targetSdkVersion set to? According to the Android docs, the attribute android:layout_alignStart is defined starting with API Level 17.

Hi @Ajay,

Thanks for your reply.

Yes, It was 16. But when I change it to 21, the error is still there.

Related settings in AndroidManifest.xml

<uses-sdk android:minSdkVersion=“10” android:targetSdkVersion=“21”/>

<meta-data android:name=“com.facebook.sdk.ApplicationId” android:value="\ 1111213234242xx" />

<activity android:name=“com.facebook.FacebookActivity”

         android:configChanges=“keyboard|keyboardHidden|screenLayout|screenSize|orientation”

         android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity android:name=“plugin.facebook.v4.FacebookFragmentActivity”

         android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

         android:configChanges=“keyboardHidden|screenSize|orientation”/>

My Enterprise daily build version is 2917

what about this error when integrate facebook v4 sdk?

" [aapt] nothing matches overlay file corona_statusbar_icon_default.png, for flavor xxhdpi-v4

     [aapt] nothing matches overlay file corona_statusbar_icon_default.png, for flavor xxxhdpi-v4

     [aapt] /Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook/res/layout/picker_title_bar.xml:44: error: No resource identifier found for attribute ‘layout_alignStart’ in package ‘android’

     [aapt] "

Hi mlhdyx,

In your AndroidManifest.xml, what is the targetSdkVersion set to? According to the Android docs, the attribute android:layout_alignStart is defined starting with API Level 17.

Hi @Ajay,

Thanks for your reply.

Yes, It was 16. But when I change it to 21, the error is still there.

Related settings in AndroidManifest.xml

<uses-sdk android:minSdkVersion=“10” android:targetSdkVersion=“21”/>

<meta-data android:name=“com.facebook.sdk.ApplicationId” android:value="\ 1111213234242xx" />

<activity android:name=“com.facebook.FacebookActivity”

         android:configChanges=“keyboard|keyboardHidden|screenLayout|screenSize|orientation”

         android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity android:name=“plugin.facebook.v4.FacebookFragmentActivity”

         android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

         android:configChanges=“keyboardHidden|screenSize|orientation”/>

My Enterprise daily build version is 2917