Skip to content

Commit a5e165c

Browse files
authored
Merge pull request #3 from defold/fbsdk5
Update to Facebook SDK 5.0 and Graph API 3.3
2 parents e68941a + 5129874 commit a5e165c

File tree

769 files changed

+13076
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

769 files changed

+13076
-1640
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ Thumbs.db
99
.cproject
1010
builtins
1111
*.pem
12+
.gradle
13+
_site
14+
Gemfile.lock

facebook/ext.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: FacebookExtExternal
33
platforms:
44
android:
55
bundle:
6-
aaptExtraPackages: ['com.facebook']
6+
aaptExtraPackages: ['com.facebook', 'com.facebook.common']
77

88
ios:
99
context:
-53.8 KB
Binary file not shown.
2.44 MB
Binary file not shown.
-686 KB
Binary file not shown.

facebook/lib/web/library_facebook.js

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -136,65 +136,6 @@ var LibraryFacebook = {
136136
console.error("Limiting Facebook Analytics is not supported for Canvas");
137137
},
138138

139-
// https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0
140-
dmFacebookDoLogin: function(state_open, state_closed, state_failed, callback, lua_state) {
141-
142-
var chainedUpdateMeAndPermissions = function() {
143-
// request user and permissions data, need to store this on the C side
144-
window._dmFacebookUpdateMe(function(e, me_data) {
145-
if (e == 0) {
146-
window._dmFacebookUpdatePermissions(function(e, permissions_data) {
147-
if (e == 0) {
148-
var me_buf = allocate(intArrayFromString(me_data), 'i8', ALLOC_STACK);
149-
var permissions_buf = allocate(intArrayFromString(permissions_data), 'i8', ALLOC_STACK);
150-
Runtime.dynCall('viiiii', callback, [lua_state, state_open, 0, me_buf, permissions_buf]);
151-
} else {
152-
var err_buf = allocate(intArrayFromString(e), 'i8', ALLOC_STACK);
153-
Runtime.dynCall('viiiii', callback, [lua_state, state_failed, err_buf, 0, 0]);
154-
}
155-
});
156-
} else {
157-
var err_buf = allocate(intArrayFromString(e), 'i8', ALLOC_STACK);
158-
Runtime.dynCall('viiiii', callback, [lua_state, state_failed, err_buf, 0, 0]);
159-
}
160-
});
161-
}
162-
163-
try {
164-
165-
FB.getLoginStatus(function(response) {
166-
167-
// The user might login with JS outside Defold,
168-
// then we only need to update the me-table and
169-
// permissions list.
170-
if (response.status === 'connected') {
171-
chainedUpdateMeAndPermissions();
172-
} else {
173-
174-
FB.login(function(response) {
175-
var e = (response && response.error ? response.error.message : 0);
176-
if (e == 0 && response.authResponse) {
177-
178-
chainedUpdateMeAndPermissions();
179-
180-
} else if (e != 0) {
181-
var err_buf = allocate(intArrayFromString(e), 'i8', ALLOC_STACK);
182-
Runtime.dynCall('viiiii', callback, [lua_state, state_closed, err_buf, 0, 0]);
183-
} else {
184-
// No authResponse. Below text is from facebook's own example of this case.
185-
e = 'User cancelled login or did not fully authorize.';
186-
var err_buf = allocate(intArrayFromString(e), 'i8', ALLOC_STACK);
187-
Runtime.dynCall('viiiii', callback, [lua_state, state_failed, err_buf, 0, 0]);
188-
}
189-
}, {scope: 'public_profile,user_friends'});
190-
191-
}
192-
});
193-
} catch (e) {
194-
console.error("Facebook login failed " + e);
195-
}
196-
},
197-
198139
dmFacebookDoLogout: function() {
199140
try {
200141
FB.logout(function(response) {
@@ -234,7 +175,7 @@ var LibraryFacebook = {
234175
}
235176
},
236177

237-
// https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0
178+
// https://developers.facebook.com/docs/reference/javascript/FB.login/v3.3
238179
// https://developers.facebook.com/docs/facebook-login/permissions/v2.0
239180
dmFacebookRequestReadPermissions: function(permissions, callback, lua_state) {
240181
try {
@@ -269,7 +210,7 @@ var LibraryFacebook = {
269210

270211
},
271212

272-
// https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0
213+
// https://developers.facebook.com/docs/reference/javascript/FB.login/v3.3
273214
// https://developers.facebook.com/docs/facebook-login/permissions/v2.0
274215
dmFacebookRequestPublishPermissions: function(permissions, audience, callback, lua_state) {
275216
try {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Building libraries for Android
2+
3+
## Build the .jar file
4+
5+
* Call `gradle build` with only the Android dependencies (see [build.gradle](build.gradle))
6+
7+
* Copy the jar file to `android-support.jar`
8+
9+
* Call `gradle build` with the Facebook dependencies (see [build.gradle](build.gradle))
10+
11+
## Repack the .jar file
12+
13+
* Create a text file containing the class files from `android-support.jar`
14+
15+
$ jar tvf android-support.jar > support.txt
16+
17+
* Repack the facebook jar file with
18+
19+
$ python repack.py ../build/package/share/java/facebooksdk-5.0.0.jar support.txt facebooksdk-5.0.0.jar
20+
21+
* Copy the `facebooksdk-5.0.0.jar` to `facebook/lib/android/facebooksdk-5.0.0.jar`
22+
23+
## Copy the resources
24+
25+
* Unpack the facebook package `facebooksdk-5.0.0.tar.gz` (generated when building the jar file)
26+
27+
$ mkdir foo
28+
$ cd foo
29+
$ tar xf ../facebooksdk-5.0.0.tar.gz
30+
31+
* Make sure the share/java/<dependency>/res/ files doesn't collide with any in the `android.jar` from the engine
32+
33+
* `http://d.defold.com/archive/<SHA1>/engine/armv7-android/android.jar`
34+
35+
* Copy the resources to the extension
36+
37+
$ python copy_resources.py foo/share/java/res/ ../../res/android/res
38+
39+
## Done!
40+
41+
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
apply plugin: 'java'
2+
3+
repositories {
4+
maven {
5+
url "https://maven.google.com/"
6+
}
7+
mavenCentral()
8+
}
9+
10+
def fbVersion = "5.0.0"
11+
12+
// * Build once with these support dependencies only
13+
// * Then run: jar tvf ./build/package/share/java/facebooksdk-5.0.0.jar > support.txt
14+
// * Then revert the support dependencies in favor of the actual fb dependencies
15+
// dependencies {
16+
// compile "com.android.support:support-v4:27.1.1"
17+
// compile "com.android.support:support-compat:27.1.1"
18+
// compile "com.android.support:support-core-utils:27.1.1"
19+
// compile "com.android.support:support-core-ui:27.1.1"
20+
// compile "com.android.support:support-media-compat:27.1.1"
21+
// compile "com.android.support:support-fragment:27.1.1"
22+
// compile "com.android.support:support-annotations:27.1.1"
23+
// }
24+
25+
dependencies {
26+
27+
// Facebook Core only (Analytics)
28+
compile "com.facebook.android:facebook-core:${fbVersion}"
29+
30+
// Facebook Login only
31+
compile "com.facebook.android:facebook-login:${fbVersion}"
32+
33+
// Facebook Share only
34+
compile "com.facebook.android:facebook-share:${fbVersion}"
35+
36+
// // Facebook Places only
37+
// compile "com.facebook.android:facebook-places:${fbVersion}"
38+
39+
// // Facebook Messenger only
40+
// compile "com.facebook.android:facebook-messenger:${fbVersion}"
41+
42+
// // Facebook App Links only
43+
// compile "com.facebook.android:facebook-applinks:${fbVersion}"
44+
45+
// Facebook Android SDK (everything)
46+
compile "com.facebook.android:facebook-android-sdk:${fbVersion}"
47+
}
48+
49+
def outputPackageName = "facebooksdk-${fbVersion}"
50+
def resultDirectory = "${project.buildDir}/result"
51+
def packedDirectory = "${resultDirectory}/packed"
52+
def aarDirectory = "${packedDirectory}/aar"
53+
def unpackedDirectory = "${resultDirectory}/unpacked"
54+
def unpackedClassesDirectory = "${unpackedDirectory}/classes"
55+
def packageOutputDirectory = "${project.buildDir}/package"
56+
def packageDirectory = "${packageOutputDirectory}/share/java"
57+
def packageResDirectory = "${packageDirectory}/res"
58+
59+
task copyArtifacts() {
60+
outputs.dir packedDirectory
61+
62+
project.configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { artifact ->
63+
println "${artifact.moduleVersion.id.group}.${artifact.name}-${artifact.moduleVersion.id.version}.${artifact.extension}"
64+
copy {
65+
from artifact.file
66+
into packedDirectory
67+
rename "(.*)", "${artifact.moduleVersion.id.group}.${artifact.name}-${artifact.moduleVersion.id.version}.${artifact.extension}"
68+
}
69+
}
70+
}
71+
72+
task unzipJars(dependsOn: copyArtifacts) {
73+
inputs.dir packedDirectory
74+
outputs.dir unpackedClassesDirectory
75+
76+
doLast {
77+
println('*** Unzip jars')
78+
fileTree(dir: packedDirectory).include('*.jar').each { lib ->
79+
copy {
80+
println "Unzip $lib.name"
81+
from zipTree(lib)
82+
into unpackedClassesDirectory
83+
exclude 'META-INF/'
84+
exclude 'NOTICE.txt'
85+
}
86+
}
87+
}
88+
}
89+
90+
task unzipAars(dependsOn: unzipJars) {
91+
inputs.dir packedDirectory
92+
outputs.dir unpackedClassesDirectory
93+
94+
doLast {
95+
println('*** Unzip aars')
96+
fileTree(dir: packedDirectory).include('*.aar').each { lib ->
97+
copy {
98+
println "Unzip $lib.name"
99+
def dirName = lib.name - '.aar'
100+
from zipTree(lib)
101+
into "${aarDirectory}/${dirName}"
102+
}
103+
}
104+
println('*** Unzip jars from aars')
105+
fileTree(dir: "${aarDirectory}").include('**/*.jar').each { lib ->
106+
copy {
107+
println "Unzip $lib.name"
108+
from zipTree(lib)
109+
into unpackedClassesDirectory
110+
exclude 'META-INF/'
111+
}
112+
}
113+
}
114+
}
115+
116+
task zipClasses(dependsOn: unzipAars, type: Zip) {
117+
from unpackedClassesDirectory
118+
archiveName "${outputPackageName}.jar"
119+
destinationDir file("${packageDirectory}")
120+
}
121+
122+
task collectResources(dependsOn: zipClasses, type:Exec) {
123+
commandLine 'python', 'extract_res.py', "${aarDirectory}", "${packageResDirectory}"
124+
}
125+
126+
task fixResPermissions(dependsOn: collectResources, type:Exec) {
127+
commandLine "chmod", "-R", "+rw", "${packageResDirectory}"
128+
}
129+
130+
task createPackage(dependsOn: fixResPermissions, type: Tar) {
131+
from packageOutputDirectory
132+
archiveName "${outputPackageName}.tar.gz"
133+
compression = Compression.GZIP
134+
destinationDir file("./")
135+
}
136+
137+
build.dependsOn createPackage
138+
139+
clean {
140+
delete "${project.buildDir}"
141+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import sys
3+
import shutil
4+
5+
def copytree(src, dst):
6+
""" https://stackoverflow.com/a/13814557/468516 """
7+
if not os.path.exists(dst):
8+
os.makedirs(dst)
9+
for item in os.listdir(src):
10+
s = os.path.join(src, item)
11+
d = os.path.join(dst, item)
12+
if os.path.isdir(s):
13+
copytree(s, d)
14+
else:
15+
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
16+
shutil.copy2(s, d)
17+
18+
def extract_res(package_name, dir, output_dir):
19+
res_path = os.path.join(dir, "res")
20+
if os.path.exists(res_path):
21+
if os.listdir(res_path):
22+
print("Copying " + package_name)
23+
output_package_dir = os.path.join(output_dir, package_name)
24+
copytree(res_path, output_package_dir)
25+
26+
27+
def iterate_and_extract(dir, output_dir):
28+
for package_name in os.listdir(dir):
29+
path = os.path.join(dir, package_name)
30+
if os.path.isdir(path):
31+
extract_res(package_name, path, output_dir)
32+
33+
# python extract_res.py build/result/packed/aar /output_directory/
34+
def main():
35+
iterate_and_extract(sys.argv[1], sys.argv[2])
36+
37+
if __name__ == "__main__":
38+
main()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
import os, sys, shutil, subprocess
3+
4+
def run(cmd, cwd=None):
5+
print "CMD", cmd
6+
print "CWD", cwd
7+
p = subprocess.Popen(cmd.split(), cwd=cwd)
8+
p.wait()
9+
10+
def unpack_jar(path, outputdir):
11+
run('jar xf %s' % path, outputdir)
12+
13+
def pack_jar(path, outputjar):
14+
run('jar cf %s .' % outputjar, path)
15+
16+
def read_excludes(path):
17+
excludes = []
18+
with open(path, 'rb') as f:
19+
for line in f.readlines():
20+
line = line.strip()
21+
if not line.endswith('.class'):
22+
continue
23+
excludes.append(line)
24+
return excludes
25+
26+
def prune_files(dir, excludes):
27+
for root, dirs, files in os.walk(dir):
28+
for f in files:
29+
full = os.path.join(root, f)
30+
relative = os.path.relpath(full, dir)
31+
if relative in excludes:
32+
print relative, "\t\tEXCLUDED"
33+
os.unlink(full)
34+
35+
36+
if __name__ == '__main__':
37+
injar = os.path.abspath(sys.argv[1])
38+
excludesfile = os.path.abspath(sys.argv[2])
39+
outputjar = os.path.abspath(sys.argv[3])
40+
tmpdir = os.path.abspath('_tmp')
41+
print "Created temp dir", tmpdir
42+
if not os.path.exists(tmpdir):
43+
os.makedirs(tmpdir)
44+
unpack_jar(injar, tmpdir)
45+
excludes = read_excludes(excludesfile)
46+
prune_files(tmpdir, excludes)
47+
pack_jar(tmpdir, outputjar)
48+
49+
shutil.rmtree(tmpdir)
50+
print "Removed temp dir", tmpdir

0 commit comments

Comments
 (0)