Databinding use Glide with kotlin can not find symbol - android

I want to DataBinding in the adapter, there is an ImageView I use Glide binding adapter, but when I test on my phone there is cannot find symbol errors. And I have to try to rebuild project, clean project, reopen android studio. And change ViewDataBinding to ItemGameNotReleasedBinding. but it still not works. Can anyone help me find where is wrong? Thanks a lot.
The error message.
cannot find symbol
import com.perfowl.youli.databinding.ItemGameNotReleasedBindingImpl;
symbol: class ItemGameNotReleasedBindingImpl
location: package com.perfowl.youli.databinding
The build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.perfowl.youli"
minSdkVersion 15
targetSdkVersion 26
versionCode 6
versionName "1.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.code.gson:gson:2.8.4'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.koushikdutta.ion:ion:2.2.1'
implementation 'com.mikhaellopez:circularimageview:3.0.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
// Json
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.6'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.6'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6"
// Rounded ImageView.
implementation 'com.makeramen:roundedimageview:2.3.0'
// Glide
implementation ('com.github.bumptech.glide:glide:4.7.1') {
exclude group: "com.android.support"
}
kapt 'com.github.bumptech.glide:compiler:4.7.1'
// Kotlin data binding.
kapt "androidx.databinding:databinding-compiler:3.3.0-alpha03"
// Firebase Crashlytics
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true
}
// U-meng analytics.
implementation 'com.umeng.sdk:common:1.5.1'
implementation 'com.umeng.sdk:analytics:7.5.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
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'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
this is my ImageHelper.kr code
package com.perfowl.youli.ui
import android.databinding.BindingAdapter
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.perfowl.youli.util.GlideApp
// Image binding
#BindingAdapter("android:src")
fun setSrc(view: ImageView, bitmap: Bitmap) {
view.setImageBitmap(bitmap)
}
#BindingAdapter("android:src")
fun setSrc(view: ImageView, resId: Int) {
view.setImageResource(resId)
}
#BindingAdapter("app:imageUrl", "app:placeHolder", "app:error")
fun loadImage(imageView: ImageView, url: String, holderDrawable: Drawable, errorDrawable: Drawable) {
var requestOptions = RequestOptions()
requestOptions = requestOptions.transforms(CenterCrop(), RoundedCorners(12))
GlideApp.with(imageView.context)
.load(url)
.centerCrop()
.apply(requestOptions)
.into(imageView)
}
this is GameNotReleasedAdapter code
#SuppressLint("InflateParams")
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var row = convertView
val game = getItem(position)
val binding: ViewDataBinding
if (row == null) {
row = inflater!!.inflate(R.layout.item_game_not_released, null)
// Binding data
binding = DataBindingUtil.inflate(
LayoutInflater.from(parent.context),
itemLayoutId,
parent,
false
)
}else binding = DataBindingUtil.getBinding(convertView!!)!!
binding.setVariable(variableId, game)
platformIconLayout = row!!.findViewById(R.id.platform_LL)
languageIconLayout = row.findViewById(R.id.language_LL)
// nameTextView.text = game!!.name
// glideUtil.loadImageWithGlide(game.cover, coverImageView)
if (game.platform!!.size > 0) {
setPlatformIcon(game.platform!!)
}
if (game.language!!.size > 0) {
setLanguageIcon(game.language!!)
}
return binding.root
}
This is item_game_not_released.xml code
<?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>
<variable
name="game"
type="com.perfowl.youli.data.db.model.Game" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="115dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<View
android:id="#+id/background"
android:layout_width="324dp"
android:layout_height="115dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#drawable/bg_item_game" />
<TextView
android:id="#+id/released_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/bg_date"
android:lineSpacingMultiplier="2.5"
android:text="#{game.releasedDate}"
android:textColor="#color/colorWhite"
android:textSize="13sp" />
<ImageView
android:id="#+id/cover"
android:layout_width="141dp"
android:layout_height="80dp"
android:layout_marginTop="25dp"
android:contentDescription="#string/game_cover"
app:imageUrl="#{game.cover}" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="#id/cover"
android:layout_alignTop="#id/cover"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toEndOf="#id/cover"
android:layout_toRightOf="#id/cover"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:text="#{game.name}"
android:textColor="#color/colorTextPrimary"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/language_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</LinearLayout>
<LinearLayout
android:id="#+id/platform_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/background"
android:layout_alignEnd="#id/background"
android:layout_alignRight="#id/background"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
</layout>

Related

databinding msg Could not find accessor within kotlin dataclass

Error message
Found data binding error(s):
[databinding] {"msg":"Could not find accessor com.dubhe.room.entity.User.name","file":"app\\src\\main\\res\\layout\\activity_add_user.xml","pos":[{"line0":31,"col0":28,"line1":31,"col1":36}]}
My layout 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">
<data>
<import
alias="user"
type="com.dubhe.room.entity.User" />
<variable
name="add"
type="android.view.View.OnClickListener" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="addUser" />
<EditText
android:id="#+id/editUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="name"
android:text="#{user.name}" /> <-error in this line.
<EditText
android:id="#+id/editUserAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="age"
android:inputType="number"
android:text="#{user.age}" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="#{add}"
android:text="Add" />
</LinearLayout>
</layout>
My entity is a kotlin data class.
#Entity(tableName = "user")
data class User(
#PrimaryKey(autoGenerate = true) #ColumnInfo(name = "user_id") var id: Int = 0,
#ColumnInfo(name = "user_name")var name: String = "",
#ColumnInfo(name = "user_age")var age: Int = 0,
#Ignore var isChecked: Boolean = false
)
build.gradle in app directory.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.dubhe.databinding"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha08'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'com.android.support:support-vector-drawable:29.0.0'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Room
implementation 'android.arch.persistence.room:runtime:2.1.4'
//BaseRecyclerViewAdapter
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46'
annotationProcessor 'android.arch.persistence.room:compiler:2.1.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
}
No matter if I clean and rebuild or Invalidate Caches, I can't compile.
You are using an import instead of a variable:
This:
<import alias="user" type="com.dubhe.room.entity.User" />
should be this:
<variable name="user" type="com.dubhe.room.entity.User" />

cannot find symbol import yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBindingImpl

I am developing football statics app but when I run the code I am getting following exception
cannot find symbol
import yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBindingImpl;
^
symbol: class FootballItemBindingImpl
below XML class
<?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>
<variable
name="viewModel"
type="yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:mutableText="#{viewModel.clubName}"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:mutableText="#{viewModel.countryName}"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:mutableText="#{viewModel.clubValue}"/>
<ImageView
app:imageUrl="#{viewModel.image}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/clubImage"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:mutableText="#{viewModel.europeanTitle}"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
below my FootballAdapter.kt where I have used databinding
import android.os.Build
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import yodgorbekkomilov.edgar.footballapp.FootballResponse
import yodgorbekkomilov.edgar.footballapp.R
import yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBinding
import yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel
class FootballAdapter :
RecyclerView.Adapter<FootballAdapter.ViewHolder>() {
private lateinit var footballList: List<FootballResponse>
fun updatePostList(footballList: List<FootballResponse>) {
this.footballList = footballList
notifyDataSetChanged()
}
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): FootballAdapter.ViewHolder {
val binding: FootballItemBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.context),
R.layout.football_item,
parent,
false
)
return ViewHolder(binding)
}
override fun getItemCount(): Int {
return footballList.size
}
#RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: FootballAdapter.ViewHolder, position: Int) {
holder.bind(footballList[position])
}
class ViewHolder(private val binding: FootballItemBinding) : RecyclerView.ViewHolder(binding.root) {
private val viewModel = FootballViewModel()
fun bind(model: FootballResponse) {
viewModel.bind(model)
binding.viewModel = viewModel
}
}
}
below FootballViewModel.kt
import androidx.lifecycle.MutableLiveData
import yodgorbekkomilov.edgar.footballapp.FootballResponse
import yodgorbekkomilov.edgar.footballapp.base.BaseViewModel
class FootballViewModel: BaseViewModel() {
private val clubName = MutableLiveData<String>()
private val countryName = MutableLiveData<String>()
private val clubValue = MutableLiveData<String>()
private val clubImage = MutableLiveData<String>()
private val europeanTitle = MutableLiveData<String>()
fun bind(football: FootballResponse){
clubName.value= football[0].name
countryName.value = football[1].country
clubValue.value = football[2].value.toString()
clubImage.value = football[3].image
europeanTitle.value = football[4].europeanTitles.toString()
}
fun getClubName():MutableLiveData<String>{
return clubName
}
fun getCountryName():MutableLiveData<String>{
return countryName
}
fun getClubValue():MutableLiveData<String>{
return clubValue
}
fun getImage():MutableLiveData<String> {
return clubImage
}
fun getEuropeanTitle():MutableLiveData<String> {
return europeanTitle
}
}
below my app.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "yodgorbekkomilov.edgar.footballapp"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures{
dataBinding = true
viewBinding = true
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
def room_version = "2.2.5"
def nav_version = "2.3.0"
//Navigation component
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
//RxJava
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.1"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//Room
implementation "androidx.room:room-rxjava2:$room_version"
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
//Dagger2
implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
what I have tried
1.invalidate cache restart
2. I have checked xml carefully it did not solve problem
3. tried following After migration to androidX: Databinding problem (Android Studio 4) and ActivityMainBindingImpl cannot be found in this one as well it did not solve my problem
I want to know where I am making mistake

Unable to resolve reference BR at runtime databinding android

I am trying to use databinding with MVVM in my android app but it is giving me an error: "Unable to resolve reference BR" at runtime while i can see the class already exist in the project.
build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.abc.xxx"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
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.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
}
ViewModel class:
class SearchViewModel : BaseObservable() {
private var searchModel = SearchModel("")
fun setSearchText(text: String){
searchModel.text = text
// notifyPropertyChanged(B)
notifyPropertyChanged(BR._all)
}
#Bindable
fun getSearchText(): String{
return searchModel.text
}
fun onSearchClicked(){
if(searchModel.text.isNullOrEmpty())
setSearchText("Error!!!")
}
}
Activity class:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val bind : ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
bind.viewModel = SearchViewModel()
bind.executePendingBindings()
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.abc.xxx.viewmodels.SearchViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="#+id/inImageSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/search_hint"
android:maxLines="1"
android:text="#={viewModel.userText}" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="#{()-> viewModel.onSearchClicked()}"
android:text="#string/search"
/>
</LinearLayout>
</layout>
So what are the changes i should do to make it work? I have tried many SO threads already but none of them is working. Please help me out.
It appears you are binding to a property that doesn't exit. You have the userText in your xml which doesn't exist. Also you are binding to a model of the viewModel, so you need to make sure your SearchModel also implements BaseObservable.
Then make sure it is not private in your viewModel or that you write appropriate getters to retrieve it. The get and set Names MUST match the property name that is labeled with bindable.
Also just an architecture comment. I'm not sure why you would create a searchViewModel and a searchModel. Seems sort of redundant, but maybe you have reasons.
Example SEARCH MODEL below
class SearchModel : BaseObservable() {
#Bindable
private var searchText = ""
fun setSearchText(text: String){
searchModel.text = text
notifyPropertyChanged(BR.searchText)
}
fun getSearchText(): String{
return searchModel.text
}
}
Then your XML needs to be bound correctly to the models property
<EditText
android:id="#+id/inImageSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/search_hint"
android:maxLines="1"
android:text="#={viewModel.searchModel.searchText}" />

RearView is not working on nougat using camera2

I am using camera2 library for custom camera. but not able to open camera's rear view in nougat devices.
My Gradle File:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.sitetrack"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
bundle {
language {
enableSplit = false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/io.netty.versions.properties'
}
// useLibrary 'org.apache.http.legacy'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.6.1"
implementation "com.squareup.retrofit2:converter-gson:2.6.1"
//Glide
implementation 'com.squareup.picasso:picasso:2.71828'
//Design
implementation 'com.google.android.material:material:1.0.0'
//Sugar
implementation 'com.github.satyan:sugar:1.5'
//Dimensions
implementation 'com.intuit.sdp:sdp-android:1.0.6'
//Library
implementation project(':loaderLibrary')
//Multidex
implementation 'com.android.support:multidex:1.0.3'
//GoogleServices
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//Custom Camera
implementation "androidx.camera:camera-core:1.0.0-alpha01"
implementation "androidx.camera:camera-camera2:1.0.0-alpha01"
//AWS
implementation 'com.amazonaws:aws-android-sdk-rekognition:2.16.4'
implementation 'com.amazonaws:aws-android-sdk-s3:2.16.4'
implementation 'com.amazonaws:aws-android-sdk-core:2.16.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Code for starting camera and changing Lens facing, clicking picture and enable flash.
fun startCamera(){
bindCameraUseCases()
facingButton.setOnClickListener {
lensFacing = if (CameraX.LensFacing.FRONT == lensFacing) CameraX.LensFacing.BACK else CameraX.LensFacing.FRONT
try {
// Only bind use cases if we can query a camera with this orientation
CameraX.getCameraWithLensFacing(lensFacing)
bindCameraUseCases()
} catch (exc: Exception) {
exc.printStackTrace()
}
}
}
private fun bindCameraUseCases() { // Make sure that there are no other use cases bound to CameraX
CameraX.unbindAll()
val metrics = DisplayMetrics().also { texture.display.getRealMetrics(it) }
val screenSize = Size(metrics.widthPixels, metrics.heightPixels)
val screenAspectRatio = Rational(metrics.widthPixels, metrics.heightPixels)
previewConfig = PreviewConfig.Builder().apply {
setLensFacing(lensFacing)
setTargetResolution(screenSize)
setTargetAspectRatio(screenAspectRatio)
setTargetRotation(windowManager.defaultDisplay.rotation)
setTargetRotation(texture.display.rotation)
}.build()
val preview = Preview(previewConfig)
preview.setOnPreviewOutputUpdateListener {
val parent = texture.parent as ViewGroup
parent.removeView(texture)
texture.surfaceTexture = it.surfaceTexture
parent.addView(texture, 0)
}
val imageCaptureConfig = ImageCaptureConfig.Builder()
.setLensFacing(lensFacing)
.setFlashMode(FlashMode.ON)
.build()
imageCapture = ImageCapture(imageCaptureConfig)
btn_take_picture.setOnClickListener {
val dir = File(Environment.getExternalStorageDirectory().toString() + "/SiteTrack/Images")
if (!dir.exists())
dir.mkdirs()
val fileName = System.currentTimeMillis().toString()
val fileFormat = ".jpg"
val imageFile = File(dir.getAbsolutePath(), fileName + fileFormat)
// Store captured image in the temporary file
imageCapture.takePicture(imageFile, object : ImageCapture.OnImageSavedListener {
override fun onImageSaved(file: File) {
startActivity(Intent(mContext, PreviewActivity::class.java)
.putExtra("actualImage", imageFile.absolutePath)
.putExtra("compressedImage", compressImage(mContext,Uri.parse(imageFile.absolutePath).toString())))
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left)
finish()
}
override fun onError(useCaseError: ImageCapture.UseCaseError, message: String, cause: Throwable?) {
Toast.makeText(mContext,message, Toast.LENGTH_LONG).show()
}
})
}
// Apply declared configs to CameraX using the same lifecycle owner
CameraX.bindToLifecycle(this, preview, imageCapture)
}
This is XML file :
<?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">
<TextureView
android:id="#+id/texture"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/btn_take_picture"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_marginBottom="#dimen/_15sdp"
android:src="#drawable/capture_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="#+id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginTop="#dimen/_15sdp"
android:background="#drawable/circle_frame_background_dark"
android:padding="#dimen/_8sdp"
android:src="#drawable/ic_close_black_24dp"
android:tint="#color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/facingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_15sdp"
android:layout_marginRight="#dimen/_20sdp"
android:background="#drawable/circle_frame_background_dark"
android:padding="#dimen/_8sdp"
android:src="#drawable/ic_facing_front"
android:tint="#color/white"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have tested this code on Pie, it is working fine but on Nougat(Moto E5), front view is working as per the expectations but Rear View is not even visible

Error while using Dagger2, Room and Databinding

im having issue with this error "error: cannot find symbol class DataBindingComponent" from app/build/generated/source/dataBinding/baseClasses/debug . i have tried all the options people suggested on internet but no help at all.
these options included:
1. clean / rebuild project
2. invalidate caches / restart
1) this is my root build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven {
url "https://maven.google.com"
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
// Sdk and tools
minSdkVersion = 17
devMinSdkVersion = 21;
devPreLollipopSdkVersion = 19;
targetSdkVersion = 27
compileSdkVersion = 27
buildToolsVersion = '27.0.3'
// App dependency
supportLibraryVersion = '27.1.1'
retrofit = "2.3.0"
okHttp = "3.5.0"
butterknife= "8.8.1"
glide = "4.7.1"
glideCompiler = "4.7.1"
rxJava = '2.1.8'
rxAndroid = '2.0.1'
dagger2 = "2.16"
// version
versionCode = 1
versionName = "1.0"
}
2) this is my module build.gradle
`apply plugin: 'com.android.application'
android {
dataBinding {
enabled = true
}
compileSdkVersion rootProject.ext.targetSdkVersion
dexOptions {
maxProcessCount 2
javaMaxHeapSize "2g"
}
defaultConfig {
applicationId "com.movecrop.shipper"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "movecrop.shipper"
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
implementation "com.android.support:customtabs:$rootProject.supportLibraryVersion"
implementation "com.android.support:design:$rootProject.supportLibraryVersion"
implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:multidex:1.0.3'
// glide
implementation "com.github.bumptech.glide:glide:$rootProject.glide"
annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glideCompiler"
implementation 'jp.wasabeef:glide-transformations:2.0.2'
// retrofit
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofit"
implementation "com.squareup.retrofit2:retrofit-mock:$rootProject.retrofit"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofit"
implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofit"
// okhttp3
implementation "com.squareup.okhttp3:okhttp:$rootProject.okHttp"
implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okHttp"
implementation 'com.squareup.okio:okio:1.13.0'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.orhanobut:hawk:2.0.1'
implementation 'com.jakewharton.byteunits:byteunits:0.9.1'
implementation 'com.github.tajchert:nammu:1.2.0'
// RxJava
implementation "io.reactivex.rxjava2:rxjava:$rootProject.ext.rxJava"
implementation "io.reactivex.rxjava2:rxandroid:$rootProject.ext.rxAndroid"
// Bottom navigation
implementation 'it.sephiroth.android.library.bottomnavigation:bottom-navigation:2.0.1-rc1'
// curl
implementation 'com.github.mrmike:Ok2Curl:master-SNAPSHOT'
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
// Dagger2
implementation "com.google.dagger:dagger-android:$rootProject.dagger2"
// Dagger2 if you use the support libraries
implementation "com.google.dagger:dagger-android-support:$rootProject.dagger2"
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.dagger2"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2"
def lifecycle_version = "1.1.1"
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
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'
}
apply plugin: 'com.google.gms.google-services'
`
Hope you guys can give me some suggestion, thanks
updated:
This is one of my activity (and its layout xml) that show error:
package com.movecrop.shipper.ui.home;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingComponent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class HomeActivity
extends AppCompatActivity
implements HomeViewModel.HomeListener,
SwitchWorkingStatusReceiver.OnSwitchWorkingStatusListener {
private HomeViewModel mHomeViewModel;
ActivityHomeBinding mBinding;
LayoutDrawerHeaderBinding mHeaderBinding;
private ActionBarDrawerToggle mActionBarDrawerToggle;
private SwitchWorkingStatusReceiver mSwitchWorkingStateReceiver = new SwitchWorkingStatusReceiver();
private static final String TAG = "HomeActivity";
public static Intent newIntent(Context context) {
Intent i = new Intent(context, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
return i;
}
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Injector.getInstance().component().inject(this);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_home);
mBinding.setHomeActivity(this);
mHomeViewModel = new HomeViewModel();
mHomeViewModel.initialize(this);
LocalBroadcastManager.getInstance(this).registerReceiver(
mSwitchWorkingStateReceiver,
SwitchWorkingStatusReceiver.getIntenFilter()
);
initDrawer();
mHomeViewModel.loadUser();
navigate(R.id.menu_dashboard);
}
}
<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"
tools:context="com.movecrop.shipper.ui.home.HomeActivity">
<data>
<variable
name="homeActivity"
type="com.movecrop.shipper.ui.home.HomeActivity" />
</data>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
app:title="#string/label_dashboard_title" />
<ImageView
android:id="#+id/imgNotification"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="right|center_vertical"
android:cropToPadding="true"
android:padding="12dp"
android:visibility="invisible" />
</FrameLayout>
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/drawerNavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:theme="#style/ThemeOverlay.AppCompat.Light"
app:headerLayout="#layout/layout_drawer_header"
app:itemBackground="#drawable/bg_menu_item_selector"
app:itemIconTint="#color/color_menu_item_selector"
app:itemTextColor="#color/colorDrawerIconTint"
app:menu="#menu/drawer">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<Button
android:id="#+id/btnToggle"
android:layout_width="wrap_content"
android:layout_height="#dimen/button_height"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginTop="40dp"
android:background="#drawable/bg_primary_button_unselected"
android:maxLines="1"
android:onClick="#{homeActivity::click}"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="#string/button_go_online"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/btnSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="32dp"
android:background="#drawable/ts_list_item"
android:drawableLeft="#drawable/ic_dm_setting"
android:drawablePadding="32dp"
android:onClick="#{homeActivity::click}"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textColor="#color/colorDrawerIconTint"
android:textStyle="bold"
android:fitsSystemWindows="true"
android:text="#string/dm_setting" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</layout>
Turns out the error comes from my dao interface for room database not dagger2 neither databinding library. hope it'll help anyone who has same problem.

Categories

Resources