diff --git a/.gitignore b/.gitignore index a72b66b484..b52f87bc2a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ realm_version_check.timestamp # Build artifacts *.so +*.dylib *.d *.o diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c54448b0..7269fc014b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Enhancements * RealmObjectSchema.isPrimaryKey(String) (#2440) +* Added support for Robolectric on Max OS X (#1867). ### Bug fixes diff --git a/build.gradle b/build.gradle index 654c3174c0..0b50e99aca 100644 --- a/build.gradle +++ b/build.gradle @@ -104,6 +104,20 @@ task installRealmJava(type:Task) { description = 'Install the Realm library and Gradle plugin into mavenLocal()' } +task installRobolectric(type:GradleBuild) { + description = 'Install the Robolectric library into example' + group = 'Install' + buildFile = file('realm/build.gradle') + tasks = ['installRobolectric'] +} + +task assembleRobolectric(type:GradleBuild) { + description = 'Assemble the Robolectric support' + group = 'Build' + buildFile = file('realm/build.gradle') + tasks = ['assembleRobolectric'] +} + task assembleExamples(type:GradleBuild) { dependsOn installGradlePlugin dependsOn installRealm @@ -174,6 +188,16 @@ task distributionPackage(type:Zip) { } } +task createRobolectricDistributionPackages(type:Zip) { + description = 'Create the Robolectric distribution package' + dependsOn assembleRobolectric + + archiveName = "realm-robolectric-darwin-${currentVersion}.zip" + destinationDir = file("${buildDir}/outputs/distribution") + + from('realm/realm-jni/build/librealm-jni-darwin.dylib') +} + task cleanRealm(type:GradleBuild) { description = 'Clean the Realm project' group = 'Clean' @@ -220,6 +244,12 @@ task uploadDistributionPackage(type: Exec) { commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-java-${currentVersion}.zip", 's3://static.realm.io/downloads/java/' } +task uploadRobolectricDistributionPackage(type: Exec) { + description = 'Upload the Robolectric distribution package to S3' + dependsOn createRobolectricDistributionPackages + commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-robolectric-darwin-${currentVersion}.zip", 's3://static.realm.io/downloads/java/' +} + task createEmptyFile(type: Exec) { group = 'Release' description = 'Create an empty file that will serve as a link on S3' diff --git a/examples/build.gradle b/examples/build.gradle index c1c2682d7a..27dcc6d7f4 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -7,7 +7,7 @@ configurations.all { } allprojects { - def currentVersion = file("${rootDir}/../version.txt").text.trim() + ext.currentVersion = file("${rootDir}/../version.txt").text.trim() buildscript { repositories { diff --git a/examples/robolectricExample/.gitignore b/examples/robolectricExample/.gitignore new file mode 100644 index 0000000000..c4c4ffc6aa --- /dev/null +++ b/examples/robolectricExample/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/examples/robolectricExample/build.gradle b/examples/robolectricExample/build.gradle new file mode 100644 index 0000000000..29cb69873d --- /dev/null +++ b/examples/robolectricExample/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'android-sdk-manager' +apply plugin: 'com.android.application' +apply plugin: 'android-command' +apply plugin: 'com.neenbedankt.android-apt' +apply plugin: 'realm-android' +apply plugin: 'realm-robolectric' + +android { + compileSdkVersion rootProject.sdkVersion + buildToolsVersion rootProject.buildTools + + defaultConfig { + applicationId 'io.realm.examples.robolectric' + targetSdkVersion 21 + minSdkVersion 15 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + } + } + + command { + events 2000 + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:23.1.0' + compile 'com.android.support:design:23.1.0' + testCompile 'io.reactivex:rxjava:1.1.0' + testCompile 'junit:junit:4.12' + testCompile "org.robolectric:robolectric:3.0" +} diff --git a/examples/robolectricExample/src/main/AndroidManifest.xml b/examples/robolectricExample/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..f06b2ed6c3 --- /dev/null +++ b/examples/robolectricExample/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/examples/robolectricExample/src/main/java/io/realm/examples/robolectric/MainActivity.java b/examples/robolectricExample/src/main/java/io/realm/examples/robolectric/MainActivity.java new file mode 100644 index 0000000000..89f60a37ca --- /dev/null +++ b/examples/robolectricExample/src/main/java/io/realm/examples/robolectric/MainActivity.java @@ -0,0 +1,29 @@ +/* + * Copyright 2016 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.examples.robolectric; + +import android.app.Activity; +import android.os.Bundle; + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/examples/robolectricExample/src/main/res/drawable-xxhdpi/ic_launcher.png b/examples/robolectricExample/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000..433021180b Binary files /dev/null and b/examples/robolectricExample/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/examples/robolectricExample/src/main/res/layout/activity_main.xml b/examples/robolectricExample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..6516002320 --- /dev/null +++ b/examples/robolectricExample/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/examples/robolectricExample/src/main/res/layout/content_main.xml b/examples/robolectricExample/src/main/res/layout/content_main.xml new file mode 100644 index 0000000000..1fb534d892 --- /dev/null +++ b/examples/robolectricExample/src/main/res/layout/content_main.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/examples/robolectricExample/src/main/res/menu/menu_main.xml b/examples/robolectricExample/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000000..a459e0a540 --- /dev/null +++ b/examples/robolectricExample/src/main/res/menu/menu_main.xml @@ -0,0 +1,9 @@ + + + diff --git a/examples/robolectricExample/src/main/res/values-v21/styles.xml b/examples/robolectricExample/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000000..6b23c86e5e --- /dev/null +++ b/examples/robolectricExample/src/main/res/values-v21/styles.xml @@ -0,0 +1,8 @@ + + + diff --git a/examples/robolectricExample/src/main/res/values-w820dp/dimens.xml b/examples/robolectricExample/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000000..63fc816444 --- /dev/null +++ b/examples/robolectricExample/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/examples/robolectricExample/src/main/res/values/colors.xml b/examples/robolectricExample/src/main/res/values/colors.xml new file mode 100644 index 0000000000..3ab3e9cbce --- /dev/null +++ b/examples/robolectricExample/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/examples/robolectricExample/src/main/res/values/dimens.xml b/examples/robolectricExample/src/main/res/values/dimens.xml new file mode 100644 index 0000000000..812cb7be0a --- /dev/null +++ b/examples/robolectricExample/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + 16dp + diff --git a/examples/robolectricExample/src/main/res/values/strings.xml b/examples/robolectricExample/src/main/res/values/strings.xml new file mode 100644 index 0000000000..c4033be75f --- /dev/null +++ b/examples/robolectricExample/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + RobolectricTest + Settings + diff --git a/examples/robolectricExample/src/main/res/values/styles.xml b/examples/robolectricExample/src/main/res/values/styles.xml new file mode 100644 index 0000000000..16dbab30f2 --- /dev/null +++ b/examples/robolectricExample/src/main/res/values/styles.xml @@ -0,0 +1,17 @@ + + + + + +