diff --git a/app/build.gradle b/app/build.gradle index 9bf6fff9d..49b485fa1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,39 +34,6 @@ apply plugin: 'kotlin-kapt' apply plugin: 'jacoco-android' apply plugin: "org.jlleitschuh.gradle.ktlint" -repositories { - google() - mavenCentral() - maven { - url "https://maven.google.com" - } - jcenter() -} - -String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] - -// Set custom app import directory -def map = [:] -def custom = new File("app/src") -if (project.hasProperty("customDir")) { - custom = file(project.property("customDir")) -} - -// Set up flavours for each custom app in the directory -if (custom.listFiles()) { - custom.eachFile() { file -> - - def fileName = file.getName() - if (fileName.startsWith(".") || - fileName.contains("test") || - fileName == "main" || - fileName.contains("Test")) { - return - } - map.put(fileName, file.getAbsolutePath()) - } -} - jacoco { toolVersion = "0.8.3" } @@ -75,9 +42,6 @@ tasks.withType(Test) { jacoco.includeNoLocationClasses = true } -def branchName = System.getenv('TRAVIS_PULL_REQUEST') ?: "false" == "false" - ? System.getenv('TRAVIS_BRANCH') ?: "local" - : System.getenv('TRAVIS_PULL_REQUEST_BRANCH') def buildNumber = System.getenv('TRAVIS_BUILD_NUMBER') ?: "dev" ext { @@ -228,96 +192,7 @@ android { } } - // Custom apps built from a json file, zim file and icon set - map.each { name, directory -> - "$name" { - println "Configuring $name" - if (name == "kiwix") { - return - } - if (file(directory + "/build.gradle").exists()) { - apply from: directory + "/build.gradle" - } - def jsonFile - if (project.hasProperty("jsonFile")) { - // Read json file from properties e.g command line - jsonFile = file(project.property("jsonFile")) - } else { - // If no file provided use the test file - jsonFile = file(directory + "/info.json") - } - def parsedJson = new JsonSlurper().parseText(jsonFile.text) - def sourceFile = file(parsedJson.zim_file) - if (!sourceFile.exists()) { - sourceFile = file(directory + "/" + parsedJson.zim_file) - } - if (parsedJson.embed_zim) { - // Place content in each lib directory for embeded zims - for (String archName : archs) { - copy { - from sourceFile - into file(directory + "/jniLibs/" + archName) - rename { String filename -> "libcontent.so" } - } - } - parsedJson.zim_file = "libcontent.so" - } - // Set custom config from json - applicationId "$parsedJson.package" - buildConfigField "boolean", "IS_CUSTOM_APP", "true" - buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim" - def filename - if (parsedJson.zim_file.lastIndexOf("/") >= 0) { - filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf("/") + 1) - } else { - filename = parsedJson.zim_file - } - buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\"" - if (project.hasProperty("zim_file_size")) { - def length = Long.parseLong(project.property("zim_file_size")) - buildConfigField "long", "ZIM_FILE_SIZE", "${length}L" - } else { - long length = sourceFile.length() - buildConfigField "long", "ZIM_FILE_SIZE", "${length}L" - } - if (project.hasProperty("version_code")) { - def version_code = project.property("version_code") - versionCode version_code.toInteger() - } else { - versionCode parsedJson.version_code.toInteger() - } - if (project.hasProperty("version_name")) { - versionName project.property("version_name") - } else { - versionName parsedJson.version_name - } - if (project.hasProperty("content_version_code")) { - def content_version_code = project.property("content_version_code") - buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code" - } else if (parsedJson.content_version_code != null) { - buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code" - } else if (project.hasProperty('version_code')) { - def version_code = project.property('version_code') - buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code" - } else if (parsedJson.version_code != null) { - buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code" - } - buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\"" - resValue "string", "app_name", "$parsedJson.app_name" - resValue "string", "app_search_string", "Search " + "$parsedJson.app_name" - } - } - } - // Set each custom apps respective source directory - sourceSets { - map.each { name, directory -> - "$name" { - setRoot directory - jni.srcDirs = [] - jniLibs.srcDir directory + "/jniLibs" - } - } } compileOptions { diff --git a/build.gradle.kts b/build.gradle.kts index c6917d6d2..4f0c10a96 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,6 +45,7 @@ allprojects { repositories { google() jcenter() + mavenCentral() } } diff --git a/custom/.gitignore b/custom/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/custom/.gitignore @@ -0,0 +1 @@ +/build diff --git a/custom/build.gradle b/custom/build.gradle new file mode 100644 index 000000000..7ac4a6119 --- /dev/null +++ b/custom/build.gradle @@ -0,0 +1,150 @@ +import groovy.json.JsonSlurper + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] + +// Set custom app import directory +def map = [:] +def custom = new File("custom/src") +if (project.hasProperty("customDir")) { + custom = file(project.property("customDir")) +} + +// Set up flavours for each custom app in the directory +if (custom.listFiles()) { + custom.eachFile() { file -> + + def fileName = file.getName() + if (fileName.startsWith(".") || + fileName.contains("test") || + fileName == "main" || + fileName.contains("Test")) { + return + } + map.put(fileName, file.getAbsolutePath()) + } +} +android { + compileSdkVersion 28 + + defaultConfig { + applicationId "org.kiwix.kiwixmobile.custom" + minSdkVersion 15 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + multiDexEnabled true + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + flavorDimensions "default" + + productFlavors { + // Custom apps built from a json file, zim file and icon set + map.each { name, directory -> + "$name" { + println "Configuring $name" + if (file(directory + "/build.gradle").exists()) { + apply from: directory + "/build.gradle" + } + def jsonFile + if (project.hasProperty("jsonFile")) { + // Read json file from properties e.g command line + jsonFile = file(project.property("jsonFile")) + } else { + // If no file provided use the test file + jsonFile = file(directory + "/info.json") + } + def parsedJson = new JsonSlurper().parseText(jsonFile.text) + def sourceFile = file(parsedJson.zim_file) + if (!sourceFile.exists()) { + sourceFile = file(directory + "/" + parsedJson.zim_file) + } + if (parsedJson.embed_zim) { + // Place content in each lib directory for embeded zims + for (String archName : archs) { + copy { + from sourceFile + into file(directory + "/jniLibs/" + archName) + rename { String filename -> "libcontent.so" } + } + } + parsedJson.zim_file = "libcontent.so" + } + // Set custom config from json + applicationId "$parsedJson.package" + buildConfigField "boolean", "IS_CUSTOM_APP", "true" + buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim" + def filename + if (parsedJson.zim_file.lastIndexOf("/") >= 0) { + filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf("/") + 1) + } else { + filename = parsedJson.zim_file + } + buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\"" + if (project.hasProperty("zim_file_size")) { + def length = Long.parseLong(project.property("zim_file_size")) + buildConfigField "long", "ZIM_FILE_SIZE", "${length}L" + } else { + long length = sourceFile.length() + buildConfigField "long", "ZIM_FILE_SIZE", "${length}L" + } + if (project.hasProperty("version_code")) { + def version_code = project.property("version_code") + versionCode version_code.toInteger() + } else { + versionCode parsedJson.version_code.toInteger() + } + if (project.hasProperty("version_name")) { + versionName project.property("version_name") + } else { + versionName parsedJson.version_name + } + if (project.hasProperty("content_version_code")) { + def content_version_code = project.property("content_version_code") + buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code" + } else if (parsedJson.content_version_code != null) { + buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code" + } else if (project.hasProperty('version_code')) { + def version_code = project.property('version_code') + buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code" + } else if (parsedJson.version_code != null) { + buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code" + } + buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\"" + resValue "string", "app_name", "$parsedJson.app_name" + resValue "string", "app_search_string", "Search " + "$parsedJson.app_name" + } + } + } + // Set each custom apps respective source directory + sourceSets { + map.each { name, directory -> + "$name" { + setRoot directory + jni.srcDirs = [] + jniLibs.srcDir directory + "/jniLibs" + } + } + } + + compileOptions { + encoding = "UTF-8" + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation project(':core') +} diff --git a/custom/proguard-rules.pro b/custom/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/custom/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/custom/src/androidTest/java/org/kiwix/kiwixmobile/custom/ExampleInstrumentedTest.kt b/custom/src/androidTest/java/org/kiwix/kiwixmobile/custom/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..2c59d535a --- /dev/null +++ b/custom/src/androidTest/java/org/kiwix/kiwixmobile/custom/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package org.kiwix.kiwixmobile.custom + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("org.kiwix.kiwixmobile.custom", appContext.packageName) + } +} diff --git a/app/src/customexample/AndroidManifest.xml b/custom/src/customexample/AndroidManifest.xml similarity index 100% rename from app/src/customexample/AndroidManifest.xml rename to custom/src/customexample/AndroidManifest.xml diff --git a/app/src/customexample/build.gradle b/custom/src/customexample/build.gradle similarity index 100% rename from app/src/customexample/build.gradle rename to custom/src/customexample/build.gradle diff --git a/app/src/customexample/info.json b/custom/src/customexample/info.json similarity index 100% rename from app/src/customexample/info.json rename to custom/src/customexample/info.json diff --git a/app/src/customexample/res/drawable-hdpi/ic_kiwix_widget.png b/custom/src/customexample/res/drawable-hdpi/ic_kiwix_widget.png similarity index 100% rename from app/src/customexample/res/drawable-hdpi/ic_kiwix_widget.png rename to custom/src/customexample/res/drawable-hdpi/ic_kiwix_widget.png diff --git a/app/src/customexample/res/drawable-mdpi/ic_kiwix_widget.png b/custom/src/customexample/res/drawable-mdpi/ic_kiwix_widget.png similarity index 100% rename from app/src/customexample/res/drawable-mdpi/ic_kiwix_widget.png rename to custom/src/customexample/res/drawable-mdpi/ic_kiwix_widget.png diff --git a/app/src/customexample/res/drawable-xhdpi/ic_kiwix_widget.png b/custom/src/customexample/res/drawable-xhdpi/ic_kiwix_widget.png similarity index 100% rename from app/src/customexample/res/drawable-xhdpi/ic_kiwix_widget.png rename to custom/src/customexample/res/drawable-xhdpi/ic_kiwix_widget.png diff --git a/app/src/customexample/res/drawable-xxhdpi/ic_kiwix_widget.png b/custom/src/customexample/res/drawable-xxhdpi/ic_kiwix_widget.png similarity index 100% rename from app/src/customexample/res/drawable-xxhdpi/ic_kiwix_widget.png rename to custom/src/customexample/res/drawable-xxhdpi/ic_kiwix_widget.png diff --git a/app/src/customexample/res/drawable-xxxhdpi/ic_kiwix_widget.png b/custom/src/customexample/res/drawable-xxxhdpi/ic_kiwix_widget.png similarity index 100% rename from app/src/customexample/res/drawable-xxxhdpi/ic_kiwix_widget.png rename to custom/src/customexample/res/drawable-xxxhdpi/ic_kiwix_widget.png diff --git a/app/src/customexample/res/drawable/kiwix_icon_with_title.png b/custom/src/customexample/res/drawable/kiwix_icon_with_title.png similarity index 100% rename from app/src/customexample/res/drawable/kiwix_icon_with_title.png rename to custom/src/customexample/res/drawable/kiwix_icon_with_title.png diff --git a/app/src/customexample/res/mipmap-hdpi/kiwix_icon.png b/custom/src/customexample/res/mipmap-hdpi/kiwix_icon.png similarity index 100% rename from app/src/customexample/res/mipmap-hdpi/kiwix_icon.png rename to custom/src/customexample/res/mipmap-hdpi/kiwix_icon.png diff --git a/app/src/customexample/res/mipmap-mdpi/kiwix_icon.png b/custom/src/customexample/res/mipmap-mdpi/kiwix_icon.png similarity index 100% rename from app/src/customexample/res/mipmap-mdpi/kiwix_icon.png rename to custom/src/customexample/res/mipmap-mdpi/kiwix_icon.png diff --git a/app/src/customexample/res/mipmap-xhdpi/kiwix_icon.png b/custom/src/customexample/res/mipmap-xhdpi/kiwix_icon.png similarity index 100% rename from app/src/customexample/res/mipmap-xhdpi/kiwix_icon.png rename to custom/src/customexample/res/mipmap-xhdpi/kiwix_icon.png diff --git a/app/src/customexample/res/mipmap-xxhdpi/kiwix_icon.png b/custom/src/customexample/res/mipmap-xxhdpi/kiwix_icon.png similarity index 100% rename from app/src/customexample/res/mipmap-xxhdpi/kiwix_icon.png rename to custom/src/customexample/res/mipmap-xxhdpi/kiwix_icon.png diff --git a/app/src/customexample/res/mipmap-xxxhdpi/kiwix_icon.png b/custom/src/customexample/res/mipmap-xxxhdpi/kiwix_icon.png similarity index 100% rename from app/src/customexample/res/mipmap-xxxhdpi/kiwix_icon.png rename to custom/src/customexample/res/mipmap-xxxhdpi/kiwix_icon.png diff --git a/app/src/customexample/res/values/strings.xml b/custom/src/customexample/res/values/strings.xml similarity index 100% rename from app/src/customexample/res/values/strings.xml rename to custom/src/customexample/res/values/strings.xml diff --git a/custom/src/main/AndroidManifest.xml b/custom/src/main/AndroidManifest.xml new file mode 100644 index 000000000..b141a0d18 --- /dev/null +++ b/custom/src/main/AndroidManifest.xml @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/custom/src/test/java/org/kiwix/kiwixmobile/custom/ExampleUnitTest.kt b/custom/src/test/java/org/kiwix/kiwixmobile/custom/ExampleUnitTest.kt new file mode 100644 index 000000000..b7bf49c18 --- /dev/null +++ b/custom/src/test/java/org/kiwix/kiwixmobile/custom/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package org.kiwix.kiwixmobile.custom + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/settings.gradle b/settings.gradle index 4f519356c..632f13724 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,3 @@ include ':core' include ':app' +include ':custom'