I'm trying to use Androidx. The app is pretty new, so there is not much code. I did use the "Refactor to Androidx" option in android studio. But sometime after that, it stopped working. I don't know what made it stop working.
What am I supposed to do?
But it get this error
Error inflating class androidx.constraintlayout.widget.ConstraintLayout
Main activity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
pick_image.setOnClickListener {
toast("Pick image clicked")
}
}
}
XML
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/pick_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Pick image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.alvarlagerlof.blurr"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Androidx
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
// Testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}
EDITED 2: Since the newer version, they've reverted back to androidx.constraintlayout.widget.ConstraintLayout.
Just keep reading if you're using constraint layout version 1.1.1
EDITED: As Arturo Mejia's answer, just press ⇧⌘R or Ctrl + Shift + R to
replace any
androidx.constraintlayout.widget.ConstraintLayout
with
androidx.constraintlayout.ConstraintLayout
in all XML file that use Constraint Layout.
That's a change since constraint layout version v1.1.1 (in v1.1.0 ConstraintLayout class is still inside ".widget" package)
Old workaround answer:
Change from
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
I tried to press Command + Click at ConstraintLayout in
androidx.constraintlayout.widget.ConstraintLayout from XML file to
show the original class but it doesn't find any thing. After I edited
the constraint layout version to 1.1.0 then it's there.
In my case updating dependency
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
has helped
I fixed it by changing the gradle dependencies form alpha3 to alpha1
Related
[![I want bottom bar like this][1]][1]
Using below library in android to customize bottom tab bar :
https://github.com/Droppers/AnimatedBottomBar
It is quite easy to use and provide many animation.
But, I don't want the menu text content to display in bottom bar.
I want only icons to display while it is selected or not selected.
How can I achieve with this library?
Or Is there any way to acheive such thing?
I went through the library mentioned, it does not support this feature currently, but we can tweak the code to make it work for your usecase, but to do that you need to include the code as a module/folder instead instead of dependency.
To achieve that, you need to follow below steps
You need to get rid of dependency of implementation 'nl.joery.animatedbottombar:library:1.0.9'
Clean project to remove it from cache
you can clone the code, add 'library' folder from code as a Android module, then include it in your gradle using implementation project(path: ':library')
Once above steps are done, you can modify the code to your needs. Now for your use case, do replace updateTabType method present at line#99 inside library/src/main/java/nl/joery/animatedbottombar/TabView.kt file to below
private fun updateTabType() {
animatedView = icon_layout
selectedAnimatedView = icon_layout //here we are forcing it use icon_layout for both views all the time
if (selectedAnimatedView.visibility == View.VISIBLE) {
animatedView.visibility = View.VISIBLE
selectedAnimatedView.visibility = View.INVISIBLE
} else {
animatedView.visibility = View.INVISIBLE
selectedAnimatedView.visibility = View.VISIBLE
}
bringViewsToFront()
}
Also the library is licensed under MIT Open Source License, so you can
happily change your own version of code free of cost.
Update
Also, in library modules gradle, please remove references to bintray, that is not required
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0.9"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.61"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.android:flexbox:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.navigation:navigation-ui-ktx:2.3.1"
}
If you see in the description of the repo, you will see there are some attributes regarding the tab appearance
add this app:abb_selectedTabType = "icon" to the code that you might have already added in the xml like below
<nl.joery.animatedbottombar.AnimatedBottomBar
android:id="#+id/bottom_bar"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:abb_selectedTabType="text"
app:abb_indicatorAppearance="round"
app:abb_indicatorMargin="16dp"
app:abb_indicatorHeight="4dp"
app:abb_tabs="#menu/tabs"
app:abb_selectedTabType = "icon"
app:abb_selectedIndex="1" />
I'm having issues in my app after implementing the biometric library from androidx on a device with Android 7. The issues started in my main app when changing the font size in the phone's accessibility settings and the text size in the app didn't change. After pinpointing the problem, I have created a dummy app with a single "hello world" activity and I have found out that even only by declaring the library's dependency in app.gradle reproduces the bug.
This is the activity's xml:
<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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the build.gradle:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fontscaletestapplication"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "androidx.biometric:biometric:1.0.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Worth mentioning is that if I remove the dependency for androidx biometric, the font scaling works without any problems, but as soon as I add the dependency, changing the font size has no impact on the size of the font in the app.
From what I noticed in the main app, I think it has something to do with the application context and the application resources, but I can't figure out what the problem is. I have tested on a HTC 10 with Android 7 and on emulator with API 24. Another thing worth mentioning is that the font scaling works on Android 9 and 10.
Is there something I'm missing?
Thank you.
It's caused by https://issuetracker.google.com/issues/140607881
According to the bug:
"All version before API 26 are affected, Android 8.0 is the first version where is possible to change font size globally with app compat 1.1.0"
"Fixed in latest AppCompat 1.2.0-alpha02"
I tested the latest 1.2.0-beta01 and the fix works. Here are all the versions of appcomat https://developer.android.com/jetpack/androidx/releases/appcompat.
in one of my projects I have started to implement dataBinding in the main activity by separating the data in a class called view, in another class called viewModel and in the model class. Using these classes and the dataBinding, the application has been compiled correctly, but when I put the classes in different packages to follow the MVVM architecture, the self-generated class named ActivityLoginBinding does not recognize the class that is inside the ViewModel package. I have already done searches of different projects to see if it was my mistake at syntax level, but they are well written. I have also noticed that all the projects are divided into different packages and work correctly. Any idea why this happens and how could it be solved? Thank you.
my xml
<?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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="student3"
type="com.juan97.prueba.ViewModel.Student3ViewModel"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".View.MainActivity">
<TextView
android:layout_marginTop="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#{student3.hint1}"/>
<TextView
android:layout_marginTop="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#{student3.hint2}"/>
</LinearLayout>
</layout>
gradle module app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.juan97.prueba"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Different packages I have:
compile error
when building the app the view i've put in appears but in the editor it is not appearing, and sometimes when i create a ImageView some of the images I pasted in the drawables causes rendering problems. I recently updated my android studio and now it is full of bugs.the image attached below is a new project, I only added image view and convert it to relative layout since constraint layout gives me a ton of errors. thank you for answering my question.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:visibility="visible"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"
android:textAppearance="#style/TextAppearance.AppCompat"
android:visibility="visible" />
<ImageView
android:id="#+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp" />
</RelativeLayout>
P.S.
the image view's src or compatsrc stuff, I've deleted it since it causes errors when building just to test it out. and when opening existing projects the app folder seems to be deleted/moved.
here is the gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.rowel.animation"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
SDK 28 is buggy and has lots of layout issues and program bugs.
you can try adding Base. to your theme's parent in styles.xml
eg:
<resource>
<style name="AppTheme" parent="Theme.AppCompat">
...
to
<resource>
<style name="AppTheme" parent="Base.Theme.AppCompat">
...
if doesn't work, then try Invalidating Cache
if that doesn't work either, try changing targetSdkVersion to 27 or below
Change your compileSdkVersion and targetSdkVersion to 27
and also change this
implementation 'com.android.support:appcompat-v7:27.1.1'
For some reason I always get confronted with the following error:
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists, is public, and has an empty constructor that is public
I was following the Guide on Android Developers yet the Error above occurs right after starting the App.
nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="#id/mainFragment">
<fragment
android:id="#+id/mainFragment"
android:name="projects.ferrari.rene.sken.ui.main.MainFragment"
android:label="main_fragment"
tools:layout="#layout/main_fragment" >
<action
android:id="#+id/action_mainFragment_to_takeImageFragment"
app:destination="#id/takeImageFragment" />
</fragment>
<fragment
android:id="#+id/takeImageFragment"
android:name="projects.ferrari.rene.sken.ui.takeimage.TakeImageFragment"
android:label="take_image_fragment"
tools:layout="#layout/take_image_fragment" />
activity_main.xml
<?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"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="#navigation/nav_graph"
app:defaultNavHost="true"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package projects.ferrari.rene.sken
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
}
override fun onSupportNavigateUp()
= findNavController(R.id.my_nav_host_fragment).navigateUp()
}
build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 'android-P'
defaultConfig {
applicationId "projects.ferrari.rene.sken"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def anko_version = "0.10.5"
def nav_version = "1.0.0-alpha01"
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
implementation 'com.github.pqpo:SmartCropper:v1.1.3#aar'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
}
Basically I am using Kotlin, AndroidX and targeting Android P. I really can't figure out where the problem lies.
EDIT There might be an issue with the import. For navigation I don't import it using AndroidX. In Build your first App with Jetpack they use implementation 'androidx.navigation:navigation-fragment:' + rootProject.navigationVersion yet I could not figure out which version they were using so I read the Architecture Component Release Notes where it says for AndroidX '2.0.0-alpha1' should be used. Unfortunately this can not be resolved.
For Java:
dependencies {
def nav_version = "2.3+"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
}
For Kotlin:
dependencies {
def nav_version = "2.3+"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}