How to configure retrolambda for android6(API23) - android

I want to add Java8 support to my project. The only suitable solution I found is retrolambda gradle plugin project. Here is my build.gradle files for a project and module relatively.
Note: Please don't suggest migrate to Android Studio 3, because I want to understand why it is not working.
project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module build.gradle
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 15
targetSdkVersion 23
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
}
}
retrolambda {
javaVersion JavaVersion.VERSION_1_7
defaultMethods true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
The app itself is pretty simple. It has only one default activity, with Java8 code, like this:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> strings = new ArrayList<>();
strings.add("Hello");
strings.add("World");
strings.stream().forEach(System.out::println);
}
}
When start the app I get following an error:
FATAL EXCEPTION: main
Process: com.slesh.mtbbank, PID: 25338
java.lang.NoSuchMethodError: No interface method
stream()Ljava/util/stream/Stream; in class Ljava/util/List; or its
super classes (declaration of 'java.util.List' appears in
/system/framework/core-libart.jar)
at com.slesh.mtbbank.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6303)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
What is missed? Any ideas why it doesn't work?
Thanks in advance!

strings.stream().forEach(System.out::println)
Retrolambda does only what its name suggests: it allows you to use lambdas. It does not support streams. There are libraries that backport stream API, but retrolambda does not.

Related

Android O StorageManager new methods get NoSuchMethodError

I'm running Andorid studio 3.0 Canary 1.
The device runs Android O preview
This is my app's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-O'
buildToolsVersion '26.0.0-rc2'
defaultConfig {
applicationId "com.testqouta"
minSdkVersion 19
targetSdkVersion 'O'
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:26.0.0-beta1'
}
This is the project's build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When I try to execute this lines:
StorageManager storageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
storageManager.getCacheQuotaBytes(storageManager.getUuidForPath(getCacheDir()));
My app crashes with this exception:
java.lang.NoSuchMethodError: No virtual method getCacheQuotaBytes(Ljava/util/UUID;)J in class Landroid/os/storage/StorageManager; or its super classes (declaration of 'android.os.storage.StorageManager' appears in /system/framework/framework.jar)
at com.testqouta.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6767)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1195)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2699)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6408)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:232)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
The app crashes both on getCacheQuotaBytes and getUuidForPath.
It's worth mention that these methods are from the new Android O API.

why does dagger 2 generated components gets deleted on project rebuild?

The problem exists when the code that uses the generated 'Dagger' prefixed on a component is not commented out. If it was commented out, the generated Dagger 2 files are generated.
BookModule
#Module
public class BookModule {
#Provides
public Book providesBook(){
return new Book();
}
}
BookComponent
#Component(modules = BookModule.class)
public interface BookComponent {
void inject(MainActivity activity);
public Book getBook();
}
MainApplication
public class MainApplication extends Application {
public static BookComponent mBookComponent;
#Override
public void onCreate() {
super.onCreate();
mBookComponent = DaggerBookComponent.builder().bookModule(new BookModule()).build();
}
}
Build.gradle(Application)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.gradle(Project)
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.bryan.myapplication"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions{
enabled = true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile group: 'com.google.dagger', name: 'dagger', version: '2.10-rc1'
apt group: 'com.google.dagger', name: 'dagger-compiler', version: '2.10-rc1'
compile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3'
}
Error Stacktrace
ERROR: C:\bin\AndroidProjects\MyApplication\app\src\main\java\com\example\lloyd\myapplication\MainApplication.java:12.26: DaggerBookComponent cannot be resolved
com.android.jack.api.v01.CompilationException: Failed to compile
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:144)
at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1931)
at com.android.build.gradle.tasks.JackTask.doMinification(JackTask.java:148)
at com.android.build.gradle.tasks.JackTask.access$000(JackTask.java:73)
at com.android.build.gradle.tasks.JackTask$1.run(JackTask.java:112)
at com.android.builder.tasks.Job.runTask(Job.java:51)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:223)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.jack.frontend.FrontendCompilationException: Failed to compile
at com.android.jack.Jack.buildSession(Jack.java:1053)
at com.android.jack.Jack.run(Jack.java:540)
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:124)
... 8 more
mBookComponent = DaggerBookComponent.builder().bookModule(new BookModule()).build();
The code from above is in the MainApplication and it is the problem, if I commented it out, it rebuilds completely fine. But when I left it as it is, it got an error saying the 'DaggerBookComponent' cannot be resolved, by this time the generated DaggerBookComponent is deleted which results in cannot be resolved
When you do a rebuild, the build system looks at the Dagger module and component classes and generates the actual classes that make all of dagger work. When you do a normal incremental build, it doesn't (it assumes the old versions are still good). This means when you rebuild if there's some error in your program or in your dagger components/modules it will not be able to rebuild these files.
So basically, you have a bug somewhere, likely (although not necessarily) in your dagger setup. When you fix it, you'll stop having problems.

Android error while adding AdMob

I have a problem with ads from AdMob. I do everything as written here.
Here is my code:
Graddle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.chesshorse.chesshorse"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
buildTypes {
// release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
debug {
debuggable true
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.google.firebase:firebase-ads:10.2.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Graddle sync corectly, but when i compile my app and run in debugger app is immediately closing with this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chesshorse.chesshorse, PID: 2260
java.lang.NoSuchMethodError: No static method zzb(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzac; or its super classes (declaration of 'com.google.android.gms.common.internal.zzac' appears in /data/app/com.chesshorse.chesshorse-2/base.apk)
at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5853)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
Has anyone encountered this error? I look at other stack questions, but none helped. Could anyone tell me where I made a mistake?

No virtual method com_polidea_rxandroidble_internal_radio_RxBleRadioImpl$$Lambda$1_lambda$new$0()V

I am new in Android Developement and I try to implement Bluetooth LE features on my app.
I have some difficulties to run my android project with RXAndroidBLE.
This library use lambda and I am not able to make it run.
I have updated my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.maxime.applicationtest"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile "com.polidea.rxandroidble:rxandroidble:1.1.0"
}
When I try to run the following code in my MainActivity, an error is displayed:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RxBleClient rxBleClient = RxBleClient.create(this);
Subscription scanSubscription = rxBleClient.scanBleDevices()
.subscribe(
rxBleScanResult -> {
// Process scan result here.
Log.e("DEVICE", rxBleScanResult.getBleDevice().getName());
},
throwable -> {
// Handle an error here.
}
);
// When done, just unsubscribe.
scanSubscription.unsubscribe();
}
FATAL EXCEPTION: Thread-4847
Process: com.example.maxime.applicationtest, PID: 27342
java.lang.NoSuchMethodError: No virtual method com_polidea_rxandroidble_internal_radio_RxBleRadioImpl$$Lambda$1_lambda$new$0()V in class Lcom/polidea/rxandroidble/internal/radio/RxBleRadioImpl; or its super classes (declaration of 'com.polidea.rxandroidble.internal.radio.RxBleRadioImpl' appears in /data/app/com.example.maxime.applicationtest-1/base.apk)
at com.polidea.rxandroidble.internal.radio.RxBleRadioImpl$$Lambda$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:818)
I've no idea why it goes wrong.
If anyone could help me it would be great.
Thanks!
I finally found a solution by removing jackOptions.
Now it works like a charm.
Had this problem too. But just removing jackOptions didn't work. Had to add retrolambda to my project. My build gradle now looks like this :
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
}
}
repositories {
mavenLocal()
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.trump.islove"
minSdkVersion 18
targetSdkVersion 24
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
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile "com.polidea.rxandroidble:rxandroidble:1.1.0"
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
testCompile 'junit:junit:4.12'
}
you must write to your build.gradle file:
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
}
}

multiple dex error after add google-services

I'm using crosswalk browser to make android hybrid application.
I added firebase messaging file, but it doesn't work in some of android device.
Here is my error text.
Error:Execution failed for task ':app:transformClassesWithDexForArmv7Debug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;
And here is my application build file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 18
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'
}
}
/*crossWalk*/
productFlavors {
armv7 {
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
ndk {
abiFilters "x86", ""
}
}
}
}
repositories {
/*crossWalk*/
maven {
url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'org.xwalk:xwalk_core_library:10.39.235.15'
compile 'junit:junit:4.12'
compile ('com.google.firebase:firebase-messaging:9.6.1'){
exclude group: 'com.google.android.gms'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
And here is my project build file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
How can I build this application again?
Please help me
because google play service package is big it should use multidex, therefore use multidex dependencies like this
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 25
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
and in your launcher activity or an activity that extended from Application initialize it
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

Categories

Resources