Skip to content

Commit

Permalink
Make sure the dev uses minsdk 15 as Facebook SDK requires that
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jun 27, 2016
1 parent 81dbe94 commit 5b4f6fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.facebookconnect"
version="1.7.1.1">
version="1.7.1.2">

<name>Facebook</name>

Expand All @@ -22,6 +22,7 @@
<engines>
<engine name="cordova-android" version=">=3.6.0" />
<engine name="cordova-ios" version=">=3.5.0" />
<engine name="cordova-plugman" version=">=4.2.0"/>
</engines>

<!-- JavaScript interface -->
Expand All @@ -42,7 +43,7 @@
<access origin="https://api.facebook.com" />
<access origin="https://*.fbcdn.net" />
<access origin="https://*.akamaihd.net" />
<!--<preference name="android-minSdkVersion" value="15" />-->
<preference name="android-minSdkVersion" value="15" />
</config-file>

<source-file src="src/android/facebookconnect.xml" target-dir="res/values" />
Expand All @@ -62,6 +63,8 @@

<framework src="com.facebook.android:facebook-android-sdk:4.11.+"/>

<framework src="platforms/android/facebook-minsdk-check.gradle" custom="true" type="gradleReference"/>

<!-- cordova plugin src files -->
<source-file src="src/android/ConnectPlugin.java" target-dir="src/org/apache/cordova/facebook" />

Expand Down
35 changes: 35 additions & 0 deletions src/android/facebook-minsdk-check.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def getConfigPreference(name) {
name = name.toLowerCase()
def xml = file("res/xml/config.xml").getText()
// Disable namespace awareness since Cordova doesn't use them properly
def root = new XmlParser(false, false).parseText(xml)

def ret, defaultValue
root.preference.each { it ->
def attrName = it.attribute("name")
if (attrName && attrName.toLowerCase() == name) {
if (it.attribute('default') != null) {
defaultValue = it.attribute('default');
} else {
ret = it.attribute("value")
}
}
}
return ret ? ret : defaultValue
}

if (cdvMinSdkVersion == null) {
// first check config.xml
def minSdk = getConfigPreference("android-minSdkVersion");

// if there's no minSdk defined check AndroidManifest.xml
if (!minSdk) {
def manifest = new XmlSlurper().parse(file("AndroidManifest.xml"))
manifest.children().find { it.name() == "uses-sdk" }.each {
minSdk = it.attributes().get("android:minSdkVersion")
}
}

// update the minSdk from config.xml or AndroidManifest, with a fallback to 15
ext.cdvMinSdkVersion = minSdk && minSdk.toInteger() > 15 ? minSdk : 15;
}

0 comments on commit 5b4f6fd

Please sign in to comment.