Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@SafeVarargs and Android #992

Closed
benjchristensen opened this issue Mar 26, 2014 · 19 comments
Closed

@SafeVarargs and Android #992

benjchristensen opened this issue Mar 26, 2014 · 19 comments

Comments

@benjchristensen
Copy link
Member

There is one feature of Java 7 I would really like to use ... but Android is holding it back ... it's @SafeVarargs to solve #686 "From Overloads".

Folks from the Android side ... what happens if we build code that uses @SafeVarargs? Does it break you, or does the runtime just ignore it?

The reason I wonder is because it's an annotation, so I'm wondering if the annotation actually affects bytecode or if it just isn't seen at runtime if running on Java 6.

Is there some kind of Android "test suite" we can run against a Jar to validate the byte code is all valid?

@benjchristensen
Copy link
Member Author

/cc @mttkay @jmhofer @zsxwing

@DylanSale
Copy link

Looks like it was added in API 19 (
http://developer.android.com/reference/java/lang/SafeVarargs.html). It
seems to just be a compile time annotation. I'll download SDK 19 and test
it.

On 27 March 2014 09:41, Ben Christensen notifications@github.com wrote:

/cc @mttkay https://github.com/mttkay @jmhoferhttps://github.com/jmhofer
@zsxwing https://github.com/zsxwing

Reply to this email directly or view it on GitHubhttps://github.com//issues/992#issuecomment-38752214
.

@DylanSale
Copy link

It seems to work, even when running on an ICS (api 14) device, though the
target api must be set to 19 for it to be imported. It is defined to have
Runtime retention.
https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/lang/SafeVarargs.java

I'm not sure how linking it against one defined in a jar using java 7 will
work out though, my java fu is not that strong.

On 27 March 2014 10:41, Dylan Sale dylan.sale@gmail.com wrote:

Looks like it was added in API 19 (
http://developer.android.com/reference/java/lang/SafeVarargs.html). It
seems to just be a compile time annotation. I'll download SDK 19 and test
it.

On 27 March 2014 09:41, Ben Christensen notifications@github.com wrote:

/cc @mttkay https://github.com/mttkay @jmhoferhttps://github.com/jmhofer
@zsxwing https://github.com/zsxwing

Reply to this email directly or view it on GitHubhttps://github.com//issues/992#issuecomment-38752214
.

@benjchristensen
Copy link
Member Author

That's great news. If I provide a jar built with Java 7 can you test linking to a jar?

@DylanSale
Copy link

Sure thing

benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Mar 27, 2014
@benjchristensen
Copy link
Member Author

I have no other obvious place to place a binary so am using Dropbox: https://www.dropbox.com/s/fkt7vlox946pig0/rxjava-core-0.17.3-SNAPSHOT.jar

This file was built using OpenJDK 1.7.0_45 with @SafeVarargs
The branch this was built from is at #994

@DylanSale
Copy link

It seems to work, though it gets a bunch of warnings while building:

Warning:Gradle: : rx/Subscriber.class(rx:Subscriber.class): major version
51 is newer than 50, the highest major version supported by this compiler.
Warning:Gradle: : rx/Observable.class(rx:Observable.class): major version
51 is newer than 50, the highest major version supported by this compiler.
Warning:Gradle: :
rx/Observable$Operator.class(rx:Observable$Operator.class): major version
51 is newer than 50, the highest major version supported by this compiler.
Warning:Gradle: : rx/functions/Func1.class(rx/functions:Func1.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Function.class(rx/functions:Function.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: : rx/Subscription.class(rx:Subscription.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Action1.class(rx/functions:Action1.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/observers/Subscribers.class(rx/observers:Subscribers.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: :
rx/subscriptions/CompositeSubscription.class(rx/subscriptions:CompositeSubscription.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: : rx/functions/Action2.class(rx/functions:Action2.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/plugins/RxJavaPlugins.class(rx/plugins:RxJavaPlugins.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/Scheduler.class(rx:Scheduler.class): major version 51
is newer than 50, the highest major version supported by this compiler.
Warning:Gradle: : rx/functions/Func2.class(rx/functions:Func2.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/FuncN.class(rx/functions:FuncN.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: :
rx/observables/ConnectableObservable.class(rx/observables:ConnectableObservable.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/subjects/BehaviorSubject.class(rx/subjects:BehaviorSubject.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: :
rx/subjects/PublishSubject.class(rx/subjects:PublishSubject.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Action0.class(rx/functions:Action0.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/subscriptions/Subscriptions.class(rx/subscriptions:Subscriptions.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: : rx/functions/Func0.class(rx/functions:Func0.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/subjects/Subject.class(rx/subjects:Subject.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: : rx/Observer.class(rx:Observer.class): major version 51 is
newer than 50, the highest major version supported by this compiler.
Warning:Gradle: : rx/functions/Func3.class(rx/functions:Func3.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: :
rx/Observable$OnSubscribe.class(rx:Observable$OnSubscribe.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Action.class(rx/functions:Action.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/schedulers/Schedulers.class(rx/schedulers:Schedulers.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: :
rx/plugins/RxJavaObservableExecutionHook.class(rx/plugins:RxJavaObservableExecutionHook.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/observables/BlockingObservable.class(rx/observables:BlockingObservable.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: :
rx/Observable$OnSubscribeFunc.class(rx:Observable$OnSubscribeFunc.class):
major version 51 is newer than 50, the highest major version supported by
this compiler.
Warning:Gradle: : rx/functions/Func9.class(rx/functions:Func9.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Func8.class(rx/functions:Func8.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Func7.class(rx/functions:Func7.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Func6.class(rx/functions:Func6.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Func5.class(rx/functions:Func5.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/functions/Func4.class(rx/functions:Func4.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.
Warning:Gradle: : rx/Scheduler$Inner.class(rx:Scheduler$Inner.class): major
version 51 is newer than 50, the highest major version supported by this
compiler.

@DylanSale
Copy link

Hmm, I'm seeing some odd behaviour with it saying missing symbols in the
log (no crashes though). I'll have a closer look tomorrow if someone else
hasn't given a better answer :)

@DylanSale
Copy link

Looks like KitKat (api 19) supports jdk 7 but you need to setup some
compiler flags in gradle turn it on.

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7

@mttkay
Copy link
Contributor

mttkay commented Mar 27, 2014

Did anyone try to build their Android project with JDK 6? We're still using JDK 6. Unfortunately my team is on a tight release schedule right now so I don't have time to look into this before next week.

Generally though, this will trigger a compile time check yes? If that's the case, the only problem I can think of off the top of my head is that the dexer might be unable to resolve the annotation when processing the RxJava JAR. Keep in mind that the dex file contains everything, including direct and transitive dependencies.

@DylanSale
Copy link

I was building with JDK 6.

@benjchristensen
Copy link
Member Author

Thanks for playing with that ... I'll spend some more time on this. It's not okay to have version 51 if people expect version 50.

What's the roadmap for Android dev being moved onto version 51 (JDK 7) and no longer requiring version 50 (JDK 6)?

@benjchristensen
Copy link
Member Author

Closing out ... failed experiment, and I found @VarArgs don't actually solve the problem anyways! #686 (comment)

@DylanSale
Copy link

I'm not sure when JDK 7 development will become the norm but it is
certainly supported using the latest build tools. You can even target older
versions of android as long as you don't use new features that require
library support.

I'm on Mac however and getting a version of JDK 7 is not proving easy.

@benjchristensen
Copy link
Member Author

I'm on Mac however and getting a version of JDK 7 is not proving easy.

What do you mean by this? It's available via Oracle: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html -> http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-macosx-x64.dmg

@DylanSale
Copy link

The download "completes" about 20mb in for me. I'm not sure why.

@benjchristensen
Copy link
Member Author

Oh how fun.

@mttkay
Copy link
Contributor

mttkay commented Mar 28, 2014

I have JDK 6 and 7 installed on my Mac back to back (I occasionally switch
via JAVA_HOME). As Dylan pointed out, Java 7 is supported with the latest
Android build tools (rev 19+), and since IIRC it's byte code compliant with
Java 6 with the exception of try-with-resources a compiled build should
work on all Android versions.

The problem I guess is one of adoption. At SoundCloud we're still stuck
with Java 6 because a testing library we use (Great Expectations) refuses
to compile under Java 7. I admit I haven't researched this further, as it
wasn't a priority for us, but I imagine others either have similar problems
or more likely, simply don't see enough value in Java 7 to bump their tool
chain.

@benjchristensen
Copy link
Member Author

Understood. My intention is for RxJava 1.0 to remain on Java 6. This SafeVarargs thing is not important enough to move to Java 7 even if it worked, but it ends up that it doesn't actually solve the problem anyways because of nested generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants