I'm using data binding library and I experience following issues in Android Studio 3.0:
somelayout.xml:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="meeting"
type="some.package.MeetingStatusResponse"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{meeting.title}"
tools:text="Title"
/>
...
</LinearLayout>
</layout>
In this place: android:text="#{meeting.title}" Android Studio 3.0 underlines the # symbol and informs about error:
Error:(29, 27) <expr> or <lambda expression> expected, got '#'
Model class is written in Kotlin if it has any relevance.
The code completion is also not working for bound classes. The application can be successfully build using both, gradle command and Android Studio run app button. So this is just editor issue.
I observe this issue on Mac. On Windows it works ok. I do not have more computers to check if it's platform related issue.
Maybe you forgot to add in gradle compileOptions ?
`sourceCompatibility JavaVersion.VERSION_1_7`
`targetCompatibility JavaVersion.VERSION_1_7`
Related
In an empty project(create from new project),Android Studio can not detect lint issue "UnusedAttribute", neither code editor display hint or run Ananlyze manually(the item is checked).
And there is no lint.xml or lint config in build.gradle file in project.
android studio screenshot
my code is
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:paddingHorizontal="52dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:paddingHorizontal is introduced in version 26, and my minSdkVersion is 16.
Also, command line
./gradlew :app:lintDebug
output:lint-results-debug.html also show no detect "UnusedAttribute" problem.
I think it is my env or ide problem, but do not know what is it.
Anyone have this problem?
Additional information:
I want a clean project to figure out this problem and create empty project. In my production project Android studio also can not detect android:paddingHorizontal issue, but can detect android:networkSecurityConfig, and command line output is here:
lint-results-debug.html screenshot
I upgraded a project to Gradle plugin 3.0.1, but during the databinding classes generation, I get the following error (and the binding classes are not generated):
error: cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.store.SetterStore.getMatchingMultiAttributeSetters(SetterStore.java:642)
at android.databinding.tool.store.SetterStore.getMultiAttributeSetterCalls(SetterStore.java:529)
at android.databinding.tool.BindingTarget.resolveMultiSetters(BindingTarget.java:221)
at android.databinding.tool.LayoutBinder.<init>(LayoutBinder.java:249)
at android.databinding.tool.DataBinder.<init>(DataBinder.java:52)
at android.databinding.tool.CompilerChef.ensureDataBinder(CompilerChef.java:90)
at android.databinding.tool.CompilerChef.sealModels(CompilerChef.java:203)
at android.databinding.annotationprocessor.ProcessExpressions.writeResourceBundle(ProcessExpressions.java:193)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
...
After some investigation, it seems that the binding class is correctly generated if I have at most 1 attribute using data binding on a given element in a layout xml. If I add a second one, I get the previous exception.
In the context of my project, the following view causes the error, but unfortunately, in a brand new project, it compiles normally.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<variable
name="title"
type="String"/>
<variable
name="visible"
type="boolean"/>
</data>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- with either text or visiblility, the project builds, but not with both -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{title}"
android:visibility="#{visible ? View.VISIBLE : View.GONE}"
/>
</RelativeLayout>
</layout>
Has anyone encountered this issue ?
I've checked online for a solution tried solutions from this page: Error: Suspicious namespace and prefix combination [NamespaceTypo] when I try create Signed APK and also errors in hello world xml but there's no solution. The funny thing is when I try to build a debug of the app or a release for tv and wear everything works well. Error:
(9) Error: Suspicious namespace and prefix combination [NamespaceTypo]
xmlns:app="http://schemas.android.com/tools"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation for issues of type "NamespaceTypo":
Accidental misspellings in namespace declarations can lead to some very
obscure error messages. This check looks for potential misspellings to help track these down.
1 errors, 0 warnings
Layout file part of the code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
A solution to this is very helpful
Instead of what you have on line 3:
xmlns:app="http://schemas.android.com/tools"
Use:
xmlns:tools="http://schemas.android.com/tools"
Please change your namespace
xmlns:app="http://schemas.android.com/tools"
to
xmlns:app="http://schemas.android.com/apk/res-auto"
Fixed the problem...I had been working on the project using Android Studio version 1.0 and got the problem when I updated to version 1.5.1 So all I did is just getting back to the old version and things were okay, I have no idea why this is the case...
You can reproduce those errors by using the tool Analyse->Inspect code in android studio.
in the xml make sure that
xmlns:app="http://schemas.android.com/apk/res-auto"
and
xmlns:tools="http://schemas.android.com/tools".
If you can write like xmlns:app="http://schemas.android.com/tools" ,you will get an error.
Recently I’ve upgraded from Android Studio 1 to Android Studio Beta 1.2.
And among other issues, it seems that the shortcut (Option + Command + L) for formatting the xml-layouts it doesn’t reorganice code any more.
In the previous version of Android Studio, if you had something like this:
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp"
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
After formatting you got the next result:
<RelativeLayout
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp">
But now I just get this message: “No lines changed. Code is already properly formatted”
Is there any kind of configuration that I’m missing it?
Thanks!
Try Ctrl+Shift+Alt+L, you should have a dialog where you can tick "Rearrange".
The Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.