Android Lint not detect UnusedAttribute - android

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

Related

ConstraintLayout 2.0 rendering problems

After updating to ConstraintLayout 2.0 I realized that even the simplest layouts can not be previewed properly in Android Studio, both on OS X and Ubuntu.
First, my setup looks like this: I'm using "androidx.constraintlayout:constraintlayout:2.0.0", the version of Android Studio is 4.0.1 (the latest stable release) on both of my computers, the version of Android Gradle plugin is 4.0.1, the version of Gradle is 6.1.1.
Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I would expect it to draw the TextView aligned to the top of the screen.
What I end up seeing instead is this:
I tried turning off the experimental rendering engine as AS warned me there might be some issues with it but to no avail.
Is there something obvious I might be missing? Since 2.0.0 was in release for 2-3 days (and the release candidate was available for a wide audience for longer than that), I assume all obvious glitches should've been resolved at this point.
Upd. AS states there is a following rendering problem:
java.lang.NoClassDefFoundError: Could not initialize class androidx.constraintlayout.widget.ConstraintLayout$LayoutParams$Table
at androidx.constraintlayout.widget.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2603)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1823)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:481)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1125)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:678)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:809)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Upd. 2 I've submitted a bug report, let's see if this is a bug with Android Studio / Constraint Layout indeed (which I think is not the case).
Ok, in my case this definitely looks like an issue with a project cache. Once I've cleaned it up (Build -> Clean Project), the layout preview started working just fine.
I am having the same issue after updating to 2.0.0, I believe this is an AS/Constraint Layout issue. Using version 1.1.3, for the time being, works just fine.
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Regular build works fine, but signed build errors on EXPECTED RESOURCE OF TYPE ID

When I build my app regularly, it builds with no errors. When I try to build the SIGNED APK, I get an error...
Error: Expected resource of type id [ResourceType]
The line of code that is flagged is...
tv = (TextView)myView.findViewById(R.id.tvTimestamp);
That ID is defined in the corresponding layout xml as follows:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
>
<!-- Clock -->
<ImageView
android:layout_width="12dp"
android:layout_height="12dp"
android:src="#drawable/ic_clock_white"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="#+id/tvTimestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="14sp"
android:layout_marginLeft="20dp"
/>
</FrameLayout>
Not sure why this one is erroring out.
Thanks
Pete
That is not a compiler error, it's a lint warning.
To solve it, try one of the following:
Clean your project and sync it again
Use View.generateViewId() to set an arbitrary id
Create an ids.xml file in res/values/
If the debug version is running correctly on the emulator/physical device then you can safely go ahead and suppress this warning by:
Clicking on the error and selecting Disable error
Adding the following lines in build.gradle
android {
lintOptions{
disable "ResourceType"
}
}

Android Studio shows errors in layout.xml

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`

Android Studio Beta 1.2 issue formatting xml-layout

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".

XML error - Doing Google Android NDK Lesson 1

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.

Categories

Resources