Hello I cannot create code impl., error like in title
Transformations.switchMap(mLiveData, listOfDamages -> { doSth()})
or
Transformations.map(liveData){
doSth()
}
I cannot applied lambda function as second parameter. Full error states
Cannot access class "android.arch.core.util.Function". Check your module classpath for missing or conflicting dependencies
I haven't any visible confilicts - mean that project is compiling
EDIT
downgrading support library from 26.1.0 to 26.0.2 and it started working
I've opened issue here:
https://issuetracker.google.com/issues/66894924
Related
I am trying to implement custom lint checks (using Kotlin). I have set up a module for my custom checks and added classes to test my first lew lint check, mostly following these two tutorials here and here.
So I now have a module, I have a custom IssueRegistry, I've created an issue and a Detector class for it. So far it seems complete. I've added a test to check if my lint check works and it looks alright.
I have added my module to the project by referencing it in settings.gradle like this: include ':app', ':somemodule', ':mylintmodule'
Now if I run the linter using ./gradlew lint I get a lint result file telling me this:
Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific API usages required by a library or a company coding style guideline.
The Lint APIs are not yet stable, so these checks may either cause a performance degradation, or stop working, or provide wrong results.
This warning flags custom lint checks that are found to be using obsolete APIs and will need to be updated to run in the current lint environment.
It may also flag issues found to be using a newer version of the API, meaning that you need to use a newer version of lint (or Android Studio or Gradle plugin etc) to work with these checks.
To suppress this error, use the issue id "ObsoleteLintCustomCheck" as explained in the Suppressing Warnings and Errors section.
So it tells me that I am using a newer API verion in my custom lint check, right? This is my custom IssueRegistry (minus some parts not relevant for this problem):
class MyCustomIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(ISSUE_NAMING_PATTERN)
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
override val minApi: Int = 1
}
From googling this problem and finding this issue I figured I have to override and set the right API version (and maybe the min API?) by overriding these properties like I did above (this version is my last attempt, directly taken from that issue).
So this property can be set to values between -1 and 5, meaning this (taken right out of the lint.detector.api class):
/** Describes the given API level */
fun describeApi(api: Int): String {
return when (api) {
5 -> "3.5+" // 3.5.0-alpha07
4 -> "3.4" // 3.4.0-alpha03
3 -> "3.3" // 3.3.0-alpha12
2 -> "3.2" // 3.2.0-alpha07
1 -> "3.1" // Initial; 3.1.0-alpha4
0 -> "3.0 and older"
-1 -> "Not specified"
else -> "Future: $api"
}
I have tried all of them, plus the one above adding a minApi override too, and I keep getting the exact same result for each of them.
Also I am unable to locate what other API version this is compared with. Is there a place where this is set for the regular linter in an Android project?
It's also unclear to me what I have to do to make sure my changes got applied - is it enough to change some code, then run lint, or do I have to compile the project first, or build & clean?
Following the tutorials, I added my custom lint check by adding this to the app's build.gradle: lintChecks project(":mylintmodule")
Is that even right? The API issue on my registry class shows up no matter if my lint check is referenced (and hopefully used) like that or not. I have also tried the other method described in the first tutorial, adding this task to the linter module build.gradle:
defaultTasks 'assemble'
task copyLintJar(type: Copy) {
description = 'Copies the lint jar file into the {user.home}/.android/lint folder.'
from('build/libs/')
into(System.getProperty("user.home") + '/.android/lint')
include("*.jar")
}
// Runs the copyLintJar task after build has completed.
build.finalizedBy(copyLintJar)
But since I can't figure out how to see if my custom checks are actually run, I don't know if that works as intended either.
So how do I get this warning resolved (since I interpret the text as "As long as the versions don't match I will not try to run your lint check"), and how can I make sure my lint check is actually run by the linter?
I am trying to customize the firebase in-app-messaging-display's UI of "Image Only" and "Modal" mode. So I turned to the official documentation, but it is quite simple, by saying:
Creating your own display is a two step process:
1.Write your own implementation of the FirebaseInAppMessagingDisplay class.
2.Register that implemenation with the headless Firebase In-App Messaging SDK.
I wonder how can I import in-app-messaging-display's source code into my project and make it work as a library.
I have downloaded its source code from github:https://github.com/firebase/firebase-android-sdk/tree/master/firebase-inappmessaging-display, tried to import it as a module, but after I selected the Source directory, Android Studio hints that: Specify location of the Gradle
or Android Eclipse project. I also have tried to copy the source code into my project's libs directory and added this: include ':libs:firebase-inappmessaging-display' into my settings.gradle file and this: implementation project(':libs:firebase-inappmessaging-display') into my app's gradle dependency. When sync building Android Studio reports errors like this:
ERROR: Unable to resolve dependency for ':XXXXXXXX': Could not resolve project :libs:firebase-inappmessaging-display.
Any suggestion will be highly appreciated.
The information on the doc is little bit confusing. I am also stuck with the same problem for long time. Actually its very simple.
Add these dependencies in your app level gradle file.
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation ("com.google.firebase:firebase-inappmessaging:17.0.3")
Register Your DisplayMessage component on starting activity.
import com.google.firebase.inappmessaging.FirebaseInAppMessaging
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay
///////
override fun onStart() {
super.onStart()
Log.e("MESSAGE", "activity started")
var firebaseInAppMessagingDisplay = FirebaseInAppMessagingDisplay { inAppMessage, cb ->
// You can show the message here.
// The variable inAppMessage has all information about the campaign that we putting in console (title, content, image url.. etc)
Log.e("MESSAGE", "Display Message callback invoked")
}
FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(firebaseInAppMessagingDisplay)
}
I have used Data binding in my existing code and now I am migrating to Room for persistence.
I have followed the steps mentioned in Florina's Blog for room
My Code builds fine without java code error or BR related error when I remove room dependency
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
and its runs too, but gives Runtime exception saying database_Impl does not exists. As it couldn't generate that's file.
But after I put Annotation processor back, it give me
Error:(29, 37) error: cannot find symbol class BR
My gradle plugin used is com.android.tools.build:gradle:3.0.1
They both don't seem to work together
Steps taken so far:
Changed BaseObservable to Observable As suggested here
Updated Android Studio to 3.0.1
Tried using gradle latest plugin canary 6
Clear, Clear Cache also done
Has anyone used Room and Data binding together ?
After 4 days of efforts I finally made my code run properly.
Steps to solve the
Data binding error like
error: package com.packagename.databinding does not exist
error: cannot find symbol class CustomMainActivityBinding
The app gradle must have below code added in order to view more than 100 errors that come by default
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "4000"
options.compilerArgs << "-Xmaxwarns" << "4000"
}
}
}
Gradle dependencies for data binding and Room arch components
annotationProcessor 'com.android.databinding:compiler:3.0.1'
implementation 'android.arch.lifecycle:extensions:1.0.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
Note: Gradle plugin version is 3.0.1
I changed my all VMs to implement Observable and call
registry.notifyChange(this, BR.bar);
in case of notify change and also implement overridden methods
#Override
public void addOnPropertyChangedCallback(OnPropertyChangedCallback
callback) {
registry.add(callback);
}
#Override
public void removeOnPropertyChangedCallback(
OnPropertyChangedCallback callback) {
registry.remove(callback);
}
These things made my code Build, but it run without exceptions when I solved the Room query related errors. Which was the main reason, code was building but not running. These errors I could see when I Rebuid my project again.
UPDATE:
After Android studio 3.1.3, Message window is gone and now all build error appears under Build view. Although there is toggle available to get textview response of error, for data-binding errors it isn't sufficient.
Solution that helped me:
In Command promt/Terminal navigate to project root.
Run this command "./gradlew build --stacktrace" if Mac or ".\gradlew
build --stacktrace" if Windows.
Now search for "error:" tag and the compile time errors will show up.
I couldn't get these errors in IDE.
In my experience, the following reasons may cause the error:
Incorrect getter/setter (missing or incorrect name)
Incorrect return type in Dao
annotationProcessor or kapt issues
The default constructor is overridden (you need to keep the empty constructor for Room)
I faced this issue while adding room dependencies. Add this in the below way to resolve the error.
def roomVersion = "2.0.0-rc01"
implementation "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"
I have some code snippets below when I use android databinding framework with ViewStub.
ItemPostBinding binding=ItemPostBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
final Post post = mDataset.get(position);
binding.stub.getViewStub().setLayoutResource(App.getPostExtensionManager().getLayout(post.getExtension()));
I kown binding.stub will be replaced with ViewStubProxy when codes compiled. But how could I ask Android Studio to ignore the error here before compiling?
(The error is Android Studio cannot resolve getViewStub() method from class ViewStub)
UPDATE 1
I don't know if it was due to my old approach of using android data-binding framework.
classpath 'com.android.databinding:dataBinder:1.0-rc4' // project build.gradle
apply plugin: 'com.android.databinding' // module build.gradle
But with the new method mentioned in the official data-binding guide, all you need to do is adding the settings below in your module's build.gradle file.
android {
....
dataBinding {
enabled = true
}
}
And the error inspections mentioned above is gone, you can even directly use binding.stub without any problem.
binding.stub.setLayoutResource(...)
binding.stub.inflate()
...
UPDATE 2
You can use binding.stub.someViewStubMethod() directly but it will fail while compiling. You still need to use binding.stub.getViewStub().someMethod(). However, just recently the error inspections is gone somehow no matter which method you add data-binding into your project by.
You are not suppose to call getViewStub method this way. binding.stub is already the ViewStub which you put in your layout item_post. You should call binding.stub.setLayoutResource()
Android Studio can't recognize ViewStubProxy correctly. Just cast it before manipulate.
import android.databinding.ViewStubProxy;
...
ViewStubProxy viewStubProxy = (ViewStubProxy)(Object)mBinding.viewStub;
if (!viewStubProxy.isInflated()) {
viewStubProxy.getViewStub().inflate();
}
Error is gone :)
I'm trying to execute a simple test case for Android following just announced unit testing support - http://tools.android.com/tech-docs/unit-testing-support
After carefully following the walkthrough I'm trying to run ./gradlew test.
I'm getting this error:
Execution failed for task ':app:compileDebugGroovy'.
> No such property: bootClasspath for class: com.android.build.gradle.AppPlugin
while using com.android.tools.build:gradle:1.1.0-rc1.
Anyone else got stuck on that?
The problem is that Groovy Android Gradle plugin (to have Groovy working on Android) isn't simply working with Android plugin in version 1.1.0-rcX.
Here's a very interesting piece of code directly from groovyx.grooid.GroovyAndroidPlugin, version 0.3.5 (current latest, here's the source)
def getRuntimeJars(Project project, plugin) {
int index
switch (getAndroidPluginVersion(project)) {
case ~/0\.9\..*/:
index = 0
break
case ~/0\.10\..*/:
case ~/0\.11\..*/:
case ~/0\.12\..*/:
case ~/0\.13\..*/:
case ~/0\.14\..*/:
case ~/1\.0\..*/:
index = 1
break
default:
index = RUNTIMEJARS_COMPAT.size()-1
}
def fun = RUNTIMEJARS_COMPAT[index]
fun(plugin)
}
and definition of RUNTIMEJARS_COMPAT:
private static List RUNTIMEJARS_COMPAT = [
{ it.runtimeJars },
{ it.bootClasspath }
]
So that API must have changed in Android Gradle between 0.9.x and 0.10.0 (yeah, I know - those Google devs change everything there :[ ). So let's take a look at that problem making class in Android Plugin version 1.0.0:
> javap -cp [path to proper jar] com.android.build.gradle.AppPlugin:
public class com.android.build.gradle.AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradle.api.Plugin<org.gradle.api.Project> {
...
public java.util.List super$2$getBootClasspath();
...
Yup! There's the method we need (coming from parent com.android.build.gradle.BasePlugin class). Now there's nothing like that in version 1.1.0-rc3. What's more, the API of com.android.build.gradle.AppPlugin is completely changed, so it's not a matter of simple if(version) to fix that.
I guess there's no chance to have Groovy Android Gradle plugin working with Unit Tests (since 1.1.0) until authors update the plugin.
Let's wait then.
That Testing Support feature is experimental. That said maybe there is no quick solution to your issue or might be a bug.
However, I would dig deeper into this, reading the message:
This line Execution failed for task ':app:compileDebugGroovy'. mentions the task, so I would go and figure what that task does. I suppose it's a delivered task. The error being that in that task there is a property missing > No such property: bootClasspath for class: com.android.build.gradle.AppPlugin
So maybe try to find that task and make sure the bootClasspath property is set for the AppPlugin class.
Try to upgrade to the new version (RC3)
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0-rc3'
// ..
}
You can also take a look here in order to compare your current setup with a working example.