Lambda expression in Android Library Module not working - java

I had an android app module which used jdk 8 and enabled Jack Options. Then I convert it to an Android Library module. And then I have to remove Jack Options from build gradle. And now the Lambda expression gives me below error when I try to build the AAR file.
Error:(59, 25) error: cannot find symbol method metafactory(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)
The code giving this error is,
Runnable r= () -> {
appManager.startApp(definition,identifier);
};
My Build Gradle is
Apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 18
targetSdkVersion 26
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(include: ['*.jar'], dir: 'libs')
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'
}
What is the reason for this problem?

On my machine I was missing the file $ANDROID_SDK/build-tools/28.0.3/core-lambda-stubs.jar, so I had to reinstall version 28.0.3 of the build tools using the Android Studio SDK manager.
(I had to check 'Show package details' to see the full list of build-tools versions)

You forgot to apply the retro lambda plugin.
Add this line to your build.gradle file:
apply plugin: 'me.tatarka.retrolambda'

Related

Using Java 8 in Android Studio 2.3.2 does not work

I have an APi that was built for Java 8.
Currently, I have Android Studio 2.3.2 on Ubuntu and to be honest, I hesitate to update it.
I used Jack and set target and source compatibility to Java Version 1.8.
When I am in debug modus, everything works as expected.
But when I want to create a signed apk I get errors like these:
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Function
I tried this one here https://github.com/evant/gradle-retrolambda
But checking the java version with "java --version" tells me that I have Java 1.8 already installed on my machine.
What can I do? I don't want to update to Android 3+
This is my gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.project.myapp"
minSdkVersion 17
targetSdkVersion 26
versionCode 12
versionName "1.055"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
jackOptions {
enabled true
}
}
buildTypes {
debug {
resValue "string", "google_maps_api_key", GoogleMapDebug
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "google_maps_api_key", GoogleMapRelease
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/asset/'] } }
}
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:design:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:cardview-v7:26.3.1'
compile 'com.android.support:support-v4:26.3.1'
compile 'com.google.android.gms:play-services-location:12.0.+'
compile 'com.google.android.gms:play-services-maps:12.0.+'
compile 'com.baoyz.swipemenulistview:library:1.3.0'
compile 'com.patrickpissurno:ripple-effect:1.3.1'
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.5.2'
compile 'com.firebaseui:firebase-ui-database:3.3.0'
compile 'com.google.firebase:firebase-auth:12.0.1'
compile 'com.firebaseui:firebase-ui:3.3.0'
compile 'com.firebaseui:firebase-ui-auth:3.3.0'
compile 'com.squareup.picasso:picasso:2.71828'
compile 'com.github.medyo:android-about-page:1.2.5'
compile 'de.codengine:tankerkoenig-api-client:1.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is the gradle (project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def keystorePropertiesFile = rootProject.file("gradle.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

Trying to build on Android

I am trying to build my app but i received this error. I have rebuilt, cleaned progect and reset Android Studio. This is the screenshot of the problem:
Code error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\User-1.gradle\caches\modules-2\files-2.1\stax\stax-api\1.0.1\49c100caf72d658aca8e58bd74a4ba90fa2b0d70\stax-api-1.0.1.jar' to 'C:\Users\User-1\Documents\workspace\WebUpHosting\app\build\intermediates\transforms\dex\debug\folders\1000\10\stax-api-1.0.1_4deeb811af0ea67608aa694ead937d7c9ac36202'
The problem is when i am building, because my app compiles right. Anyone knows how i could solve that?
UPDATE:
buil.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.webuphosting.app"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
preDexLibraries = false
}
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'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.daimajia.easing:library:2.0#aar'
compile 'com.daimajia.androidanimations:library:2.3#aar'
compile 'com.android.support:support-v4:26.+'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.android.support:recyclerview-v7:26.0.+'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile "com.squareup.retrofit2:converter-simplexml:2.3.0"
testCompile 'junit:junit:4.12'
}
Hard to tell the exact problem with more code to see, but as a solution, you could just simply disable pre-dex:
boolean preDexLibraries
Whether to pre-dex libraries. This can improve incremental builds, but clean builds may be slower.
To do so, add the following block in your main module (app)'s build.gradle file, inside the android:
android {
// everything else
dexOptions {
preDexLibraries = false
}
}
By default, it is set to true, so by setting it to false, you could get around your issue, but it may not solve the root-cause.

Gradle build error after adding facebook dependency in Android Studio

I am creating an android app currently using firebase and facebook. I am trying to add a facebook login button, but when I add the line compile 'com.facebook.android:facebook-android-sdk:[4,5)' I get the error
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute meta-data#android.support.VERSION#value value=(26.0.0-alpha1) from [com.android.support:design:26.0.0-alpha1] AndroidManifest.xml:27:9-38
is also present at [com.android.support:cardview-v7:25.3.1] AndroidManifest.xml:24:9-31 value=(25.3.1).
Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:41 to override.
when I try to sync the gradle build. Here is what my app build.gradle file looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26"
defaultConfig {
applicationId "com.notnow.barapp"
minSdkVersion 19
targetSdkVersion 26
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'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:support-v4:26.+'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
It's because Facebook library use com.android.support:cardview-v7:25.3.1 and you cannot use different support library with different version number. I resolved downgrading compileSdkVersion to 25 and all the support library to 25.3.1. You can check that Facebook library is using com.android.support:cardview-v7:25.3.1 at the following link: Facebook Core Gradle
Hope it helps.

"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync [duplicate]

This question already has answers here:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
(26 answers)
Closed 5 years ago.
I have just created a new Android Studio project for both Android Mobile and wear. The initial gradle build failed because I am getting several errors-
Error: Failed to resolve: com.android.support:support-v4:26.0.0
Error: Failed to resolve: com.android.support:percent:26.0.0
Error: Failed to resolve: com.android.support:recyclerview-v7:26.0.0
Error: Failed to resolve: com.android.support:support-annotations:26.0.0
With each error, I am given the option to Install repository and sync project, but nothing happens when I click on it. I have spent several hours trying to find why I am getting these errors, but I can't find any solutions. Does anybody know how to fix these very frustrating errors? Thank you!
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// 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 (mobile)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
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'
})
wearApp project(':wear')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:appcompat-v7:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.android.support:support-core-utils:26+"
testCompile 'junit:junit:4.12'
}
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile "com.android.support:support-core-utils:26+"
}
I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.
I don't have an Android wear project, but I had the same problem when I wanted to upgrade the Support Library version for an existing project to 26.0.0. Since 26.0.0 the support libraries are available through Google's Maven repository. So I had to add the repository to my build. gradle file.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Check out https://developer.android.com/topic/libraries/support-library/setup.html for more details.
The following worked for me:
In the Application build.gradle considered to add following:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
in the Module build.gradle:
compileSdkVersion 26
buildToolsVersion "26.0.1"
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support:animated-vector-drawable:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:percent:26.0.1'
compile 'com.android.support:wear:26.0.1'
compile 'com.google.android.support:wearable:2.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
}
Either change your build tool version from 26.0.1 to 26.0.0 or you can replace 26.0.0 by 26.+ like below.
compile 'com.android.support:support-v4:26.0.0'
to
compile 'com.android.support:support-v4:26.+"
Do same with all...
Hope it helps.
Happy Coding! ^_^
For now, I fixed this with changing in the wear build.gradle:
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
It seems like the problem is com.google.android.support:wearable:2.0.4. With that, Using 26.0.1 build tools compiles fine. I haven't gone any further with this but it looks like a dependency problem related to a repository although that is really just a guess from the error messages.
Add the following dependencies in your app/build.gradle.
repositories {
maven { url 'https://maven.fabric.io/public' }
maven{url 'https://maven.google.com'}
}
Replace this:
compile 'com.android.support:recyclerview-v7:26.0.0'
With this
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
Do same with all
Update - new version released
compile 'com.android.support:recyclerview-v7:26.1.0'
Add following dependency in your gradle
Replace
compile 'com.android.support:support-v4:26.0.0'
with
compile 'com.android.support:support-v4:25.0.0'
and Replace
compile 'com.android.support:appcompat-v7:26+'
with
compile 'com.android.support:appcompat-v7:25.0.0'
The reason that my project was giving me these errors was because I created the project for Android Platform 26. However, Wear currently doesn't support 26, and it is essential to change the target and compile SDK versions to 25 in the wear module of build.gradle.
Link to Android Developers documentation - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.findmyphone"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
}
apply plugin: 'com.google.gms.google-services'
I only needed to change the compile and target SDK versions to 25 in the wear module. I left them as 26 for the mobile module.
This one worked for me
allprojects {
repositories {
jcenter()
google()
}
}
google() does the magic with the following configuration
Studio version : 3.0 beta 2
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
I meet this problem, changing the build tool/ sdk version didn't work, clearly write compile version didn't work, off line build didn't work.
Finally I just change wearable version, and this problem gone.
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
to
provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'
By the way, I used offline building now because it is really fast when I check this issue.

"Cannot determine expansion folder" when running android Instrumentation tests

We want to set up instrumentation tests for our app, that also has 2 flavors. We have successfully set up Android Studio to run instrumented tests directly from the IDE, but trying to run instrumented tests from the command line via 'gradle connectedCheck' always results in the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDevelopmentDebugAndroidTestJavaResources'.
> Cannot determine expansion folder for /Users/james/Development/AndroidProjects/parkinsons11/app/build/intermediates/packagedJarsJavaResources/androidTest/development/debug/junit-4.12.jar936209038/LICENSE-junit.txt with folders
Our test app, which also has two flavours and is set up for instrumented tests, runs both from the IDE and from command line without incident.
Here is our gradle file from our main project:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.app.ourapp"
minSdkVersion 16
versionCode 11
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets',
'src/main/assets/font']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
live {
versionName "1.1 live"
applicationId "com.app.ourapp.live"
}
development {
versionName '1.1 development'
applicationId "com.app.ourapp.development"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library:datetimepicker')
compile project(':library:tools')
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'org.quanqi:mpandroidchart:1.7.+'
compile 'commons-io:commons-io:2.+'
compile 'joda-time:joda-time:2.+'
compile 'com.microsoft.azure.android:azure-storage-android:0.4.+'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:${robolectricVersion}"
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
And here is our gradle.build from our test app (which works):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.test.picroft.instrumentationtestapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
newFlavour {
applicationId "com.test.picroft.instrumentationtestapp.newflavor"
}
oldFlavour {
applicationId "com.test.picroft.instrumentationtestapp.oldflavor"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
I'm at a loss as to where I'm going wrong. I've compared the directory structure from both apps and there's no meaningful difference. Here's a rough outline of our main project's structure:
src
-androidTest
--java
---*
-live
--res
---layout
---values
-main
--java
---*
-test
--java
---*
I'm totally confused why instrumented tests on one app works fine both in IDE and in command line, while the other refuses to work via command line.
It seems the issue resolved itself. I believe it was some kind of corruption of the build state that was fixed through an invalidate/restart.
Its also worth pointing out that when you switch build flavours in the Build Variation panel, its worth it to wait until Android Studio finishes synchronizing and is not performing any tasks before doing a build or run. I've found that when I was hitting build or run and Android Studio hadn't finished switching the build flavour, it caused all manner of unpredictable issues.
I think the problem might be that you haven't defined a default instrumentation runner, as mentioned here. You should include this in your build.gradle file
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}

Categories

Resources