I can't use Android with Java 1.8 and Realm.
see http://stackoverflow.com/questions/36746452/realm-io-with-java-1-8-and-android
The jack option is found: http://developer.android.com/preview/j8-jack.html
Hi @mars3142
Could you be kind enough to provide us a simple example so we can reproduce the problem you are going through? We'd have hard time to fully comprehend the cause that leads to the situation above.
@mars3142, if you look at the bottom of the page that your second link goes to, you'll notice that there are a few drawbacks to using Jack currently. One of those is that Jack doesn't currently expose a way to modify your application's class files between the compilation and packaging steps.
Now, I know for a fact that this means that the android-apt plugin won't work with Jack currently, and I'm fairly sure that Realm also uses the same transformer API to do its bytecode manipulation, so it also won't work. Simply put, Jack isn't going to be an option if you want to use android-apt or Realm currently (or any library which uses android-apt, such as ButterKnife, Dagger, etc).
If you want some of the Java 8 features (such as lambdas), I would recommend _not_ using Jack for now, and instead using retrolambda. I won't go into that since there are numerous tutorials on the internet detailing that, but I can tell you that I use both retrolambda and Realm in my project and they work perfectly.
Relevant links:
Hi @bkromhout. Thanks for the detailed response and you are pretty much spot on. Realm uses both annotation processing and the Transform API, neither of which are supported by Jack right now.
And why can't you implement realm without the need for manipulating of the bytecode? Everytime Google changes the build tools, dependencies like realm and others will break. That's really bad.
You can hardly fault people for using the API's and tools that are at their disposal today? Nobody knows what will happen in the future and Jack is still very much work-in-progress.
It is fair that you want to try bleeding edge build tools, but they are clearly marked as such by Google with all the caveats that come with it.
We try to support the newest stuff as soon as possible, but trying to make Realm work with a build tool that isn't even complete yet doesn't seem like the best use of our time.
you can follow the progress of jack bytecode manipulation support here: https://code.google.com/p/android/issues/detail?id=204065
Not to mention that Google itself just started to provide first party tools to do proper bytecode manipulation in the build system (the Transform API), and that's what we waited to provide a functionality long waited for.
we waited to provide a functionality long waited for.
For those wondering, that being the ability to implement interfaces on RealmObjects (and have custom methods), and that getters/setters are no longer necessary.
So it's quite a win.
@cmelchior any update regarding this?
@shashank090789 There is still no response from google about transforming API support for JACK. See https://code.google.com/p/android/issues/detail?id=210730&q=Jack%20transform&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened
Right now in my company's project, we extract realm to another module and setup realm there, then open jack in 'app' module is fine.
@kirsting If you have time - and are allow to do so - it would be great for the community if you can share some code and comments on how you do that.
@kneth Before we move to jack, our project setup realm in 'app' module (add realm plugin to 'app' module's build.gradle file). Then we create a new module named 'core' and add realm plugin to 'core' module's build.gradle. We move all RealmObject classes and some realm relevant classes to 'core' module. Then we add 'core' module's dependency to 'app' module and remove realm plugin in 'app' module's build.gradle file.
Realm plugin is not working with jack. Since realm plugin and jack are all module level, move realm plugin and basic RealmObject classes to another module as a library. That's our thought. Sorry for my poor English explanation..
buildscript {
repositories {
mavenCentral()
jcenter()
maven {url "https://clojars.org/repo/"}
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "io.realm:realm-gradle-plugin:1.2.0"
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
and
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
android {
compileSdkVersion xx
buildToolsVersion "xx"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
works just fine for Java 8 language features (lambdas, method references, try-with-resources), btw.
@Zhuinden I have tried your idea in a clean project, but I got Error:Cannot get property 'destinationDir' on null object.
Did you get the error?
@ojarabo I have never seen that error before.
https://github.com/Zhuinden/rx-realm-recyclerview-experiment/blob/master/app/build.gradle
This example works for me...
@Zhuinden Thanks. I have checked and indeed works. My problem is that I was using jack, but I know there are other open issues regarding to jack-retrolambda-realm.
@ojarabo Jack doesn't work until https://code.google.com/p/android/issues/detail?id=210730 is resolved
@Zhuinden the good news is that the issue is now resolved :-) What would now be the next step ?
@nremond I assume Realm would need to somehow make their plugin work with Jack
@nremond now that Jack is deprecated, there is no need to support Jack
@Zhuinden Jack is deprecated? Do you have a link pointing to this?
@Zhuinden Just found the link from another issue: https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html.
Wow sad they pushed that hard and see some many people trying to support it and now have it deprecated. Law of evolution I guess :)
@maoueh The good news is that we will get Java 8 soon!
Hi, it work. Realm + Java8 + -> ;)
My Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.xxx.xxx.xxx"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:3.4.0"
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'io.reactivex:rxjava:1.1.6'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.mostafagazar:customshapeimageview:1.0.4'
compile 'com.github.bluejamesbond:textjustify-android:2.1.6'
testCompile 'junit:junit:4.12'
}
apply plugin: 'realm-android'
apply plugin: 'me.tatarka.retrolambda'
allprojects {
tasks.withType(JavaCompile) {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
@olegsoftjava You are using preview of Android Studio 3.0, right?
my Android studio 2.3.3
All info:
Android Studio 2.3.3
Build #AI-162.4069837, built on June 6, 2017
JRE: 1.8.0_112-release-b06 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
apply plugin: 'me.tatarka.retrolambda'
Yep, Retrolambda works, although when Android Studio 3.0 comes out (and Realm can finally support the build tools 3.x as well) then Retrolambda will no longer be needed
Most helpful comment
@kneth Before we move to jack, our project setup realm in 'app' module (add realm plugin to 'app' module's build.gradle file). Then we create a new module named 'core' and add realm plugin to 'core' module's build.gradle. We move all RealmObject classes and some realm relevant classes to 'core' module. Then we add 'core' module's dependency to 'app' module and remove realm plugin in 'app' module's build.gradle file.
Realm plugin is not working with jack. Since realm plugin and jack are all module level, move realm plugin and basic RealmObject classes to another module as a library. That's our thought. Sorry for my poor English explanation..