android java8 list,GitHub - SgtSilvio/android-retrofix: Backports Java 8 APIs (java.util.Optional, j...

Android RetroFix

68747470733a2f2f696d672e736869656c64732e696f2f6d6176656e2d6d657461646174612f763f636f6c6f723d627269676874677265656e266c6162656c3d677261646c65253230706c7567696e266d6574616461746155726c3d6874747073253341253246253246706c7567696e732e677261646c652e6f72672532466d32253246636f6d25324667697468756225324673677473696c76696f253246677261646c65253246616e64726f69642d726574726f666978253246636f6d2e6769746875622e73677473696c76696f2e677261646c652e616e64726f69642d726574726f6669782e677261646c652e706c7567696e2532466d6176656e2d6d657461646174612e786d6c

Backports Java 8 APIs to Android APIs < 24 (Android 7.0 Nougat)

Backported new types:

java.lang.FuncionalInterface

java.util.IntSummaryStatistics, java.util.DoubleSummaryStatistics, java.util.LongSummaryStatistics

java.util.Optional**

java.util.PrimitiveIterator**

java.util.Spliterator**

java.util.SplittableRandom

java.util.StringJoiner

java.util.concurrent.CountedCompleter

java.util.concurrent.ForkJoinPool

java.util.concurrent.ForkJoinTask

java.util.concurrent.ForkJoinWorkerTask

java.util.concurrent.RecursiveAction

java.util.concurrent.RecursiveTask

java.util.concurrent.ThreadLocalRandom

java.util.function.**

java.util.stream.**

Backported static/default methods of:

java.lang.Arrays

java.lang.Integer, java.lang.Double, java.lang.Long

java.lang.Iterable

java.lang.Objects

java.util.Collection

java.util.Comparator

java.util.Iterator

java.util.List

java.util.Map

java.util.Map$Entry

java.util.concurrent.ConcurrentMap

Backported new types:

java.util.concurrent.CompletableFuture

java.util.concurrent.CompletionException

java.util.concurrent.CompletionStage

Backported new types:

java.time.**

java.time.chrono.**

java.time.format.**

java.time.temporal.**

java.time.zone.**

Backported conversion methods of:

java.util.Date

java.util.Calendar

java.util.GregorianCalendar

java.util.TimeZone

java.sql.Date

java.sql.Time

java.sql.Timestamp

How to use

Configure your app/build.gradle like the following:

buildscript {

repositories {

google() // necessary as this plugin depends on the android gradle api

gradlePluginPortal() // where this plugin is hosted

}

dependencies {

classpath 'gradle.plugin.com.github.sgtsilvio.gradle:android-retrofix:0.3.6'

}

}

apply plugin: 'com.android.application' // mandatory for android apps

apply plugin: 'com.github.sgtsilvio.gradle.android-retrofix' // should be applied after com.android.application

...

android {

...

defaultConfig {

...

minSdkVersion 21 // has to be < 24, if you have 24+ this plugin is not needed

...

}

...

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8 // enables lambdas, method references,

targetCompatibility JavaVersion.VERSION_1_8 // default methods, static interface methods

}

...

}

dependencies {

implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.2' // for backporting streams

implementation 'net.sourceforge.streamsupport:android-retrofuture:1.7.2' // for backporting future

implementation 'org.threeten:threetenbp:1.4.4' // for backporting time

// or implementation 'com.jakewharton.threetenabp:threetenabp:1.2.4' // https://github.com/JakeWharton/ThreeTenABP

...

}

Android Studio will still display an error "Call requires API level 24 (current min is 21)".

This error is actually just a warning.

Android Studio does not know that we backport the API, so it still thinks that the API can not be used with the

minSdkVersion.

You can build and run your app without any problems.

If you want to get rid of the warning, just add @SuppressLint("NewApi") to the method or class where you use the API.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值