diff --git a/ant-prepare.sh b/ant-prepare.sh
index 13929a08c..7f41a1347 100755
--- a/ant-prepare.sh
+++ b/ant-prepare.sh
@@ -1,10 +1,14 @@
 #!/bin/bash -ex
 
+target=`sed -n 's,^target=\(.*\),\1,p' project.properties`
+
 android update lib-project --path extern/UniversalImageLoader/library
 android update lib-project --path extern/AndroidPinning
 android update lib-project --path extern/MemorizingTrustManager
 android update lib-project --path extern/libsuperuser/libsuperuser
 android update lib-project --path extern/zxing-core
+android update lib-project --path extern/android-support-v4-preferencefragment
+android update lib-project --path extern/Support/v7/appcompat --target $target
 android update project --path . --name F-Droid
 
 { echo -e "\nSuccessfully updated the main project.\n"; } 2>/dev/null
diff --git a/build.gradle b/build.gradle
index 18ba173d6..d9699d94e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -125,6 +125,15 @@ android.applicationVariants.all { variant ->
 // This is the hacky way which we force the subprojects to use the same build tools:
 // http://stackoverflow.com/a/21032272
 subprojects {
+
+	// The support-v4 library assumes certain things are defined in the 
+	// root project (which is usually the android-support project, but 
+	// this time it is the F-Droid project.
+	if (project.name.equals("support-v4")) {
+		apply plugin: 'maven'
+		rootProject.ext.supportRepoOut = ""
+	}
+
 	afterEvaluate {
 		android {
 
diff --git a/custom_rules.xml b/custom_rules.xml
index 7747834aa..5cb033506 100644
--- a/custom_rules.xml
+++ b/custom_rules.xml
@@ -1,6 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project name="custom_rules">
 
+  <target name="-pre-build">
+
+    <echo message="Copying a bunch of files around to make F-Droid and its submodules build" />
+    <copy tofile="extern/android-support-v4-preferencefragment/libs/android-support-v4.jar"
+          file="libs/android-support-v4.jar" />
+    <copy tofile="extern/Support/v7/appcompat/libs/android-support-v4.jar"
+          file="libs/android-support-v4.jar" />
+
+  </target>
+
   <target name="javadoc" description="Generate Javadocs">
     <javadoc sourcepath="${source.dir}"
              destdir="${out.dir}/javadoc"
diff --git a/project.properties b/project.properties
index 4a6e95cc5..41cb681d3 100644
--- a/project.properties
+++ b/project.properties
@@ -7,6 +7,8 @@ android.library.reference.2=extern/MemorizingTrustManager
 android.library.reference.3=extern/AndroidPinning
 android.library.reference.4=extern/libsuperuser/libsuperuser
 android.library.reference.5=extern/zxing-core
+android.library.reference.6=extern/android-support-v4-preferencefragment
+android.library.reference.7=extern/Support/v7/appcompat
 
 # For java libraries, place symlinks in extern/symlinks-for-ant-and-eclipse/
 source.dir=src;extern/symlinks-for-ant-and-eclipse