I'm following the kotlin fundamentals code lab and in it it says that anything under API 21 will convert vector images to png images and to prevent that I need to add xmlns:app="http://schemas.android.com/apk/res-auto" to the activity_main.xml file and press Sync Now, and add vectorDrawables.useSupportLibrary = true to the defaultConfig { } in the .gradle(:app) file. I followed everything but I kept getting an error:
/Users/Home/IdeaProjects/DiceRoller/app/src/main/res/layout/activity_main.xml:12
error: attribute android:srcCompat not found.
error: failed linking file resources.
I realized that the xmlns:app="http://schemas.android.com/apk/res-auto" line is grayed out
This is the gradle version I'm using:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18
What is causing this problem?
activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
tools:context=".MainActivity">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/diceImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:srcCompat="#drawable/empty_dice"
tools:src="#drawable/dice_1">
</android.support.v7.widget.AppCompatImageView>
build:grade(:app)
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.diceroller"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-beta02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
build.gradle:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is because the srcCompat attribute only exists in the app (http://schemas.android.com/apk/res-auto) namespace for the AppCompatImageView class (see the API documentation for more info), not the default android (http://schemas.android.com/apk/res/android) namespace.
To fix this, simply rename the android portion of android:srcCompat to app:srcCompat:
<android.support.v7.widget.AppCompatImageView
app:srcCompat="#drawable/empty_dice" />
(P.S. Consider self-closing the XML tag such that you don't have to write more code to close the XML element. See this question for more info)
Related
I Stuck with the problem. I have upgrade project grade to 7.0.1 and Kotlin 1.5.30. Before upgrading everything was working fine. But after upgrading, I am start getting the following error for each project. Even, I have tried to create new project also. There is also same issue I am facing. Please check the below image.
Below, I am writing all the files of my project. Which is responsible for data binding and view binding.
Project base build.gradle
buildscript {
ext.kotlin_version = '1.5.30'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application based build.gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 30
defaultConfig {
applicationId "colour.moon"
minSdk 21
targetSdk 30
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_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
dataBinding true
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
}
settings.gradle file Here this file automatically containing the given code. I though to put it here for easy understanding
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "My Application"
include ':app'
This is main file, Which is producing the error. Please check it carefully.
<?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="viewModel"
type="colour.moon.MainVM" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
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!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
When, I am converting my view to layout then the above error is coming. Please let me know, How to solved it? And If we need to remove layout then how to use data binding in the XML file!
I will be very thankful for your answer on it!
I have a very simple program that runs fine--until I add the library dependencies to connect with Firestore. Specifically, when I add implementation 'com.google.firebase:firebase-firestore:21.2.0' to my app gradle. (Changing to an earlier 17.x.x version makes no difference). The error is "Cannot fit requested classes in a single dex file", which to me makes no sense since the program is so simple: no way I have more than 64K methods running.
Here is the MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addUnitType(View view) {
return;
}
}
...here is 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">
<EditText
android:id="#+id/edit_unit_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="7dp"
android:hint="Unit Type (MedSurg, ICU, etc)"
android:inputType="text"
android:textSize="10sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
...this is the project gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
...this is the app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.nofirestore"
minSdkVersion 19
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
**implementation 'com.google.firebase:firebase-firestore:21.2.0'**
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
And again, this is the offending code in the app gradle--remove it and I am fine, put it in the dependencies and the compiling crashes:
implementation 'com.google.firebase:firebase-firestore:21.2.0'
and this the error
"Cannot fit requested classes in a single dex file"
Any thoughts on what gives? I have run much more complex apps without the need for multidex. I would love to know. Thank you.
Well, it was NOT the missing
apply plugin: 'com.google.gms.google-services'
Instead, it was something as simple as the minSdkVersion19: changing that to 22 got rid of the multidex compiling error, and it runs fine!
Inside the defaultConfig block add the following:
multiDexEnabled true
Also in the build.gradle add the following dependency:
implementation 'com.android.support:multidex:1.0.3'
You can check more information about multidex in the following link:
https://developer.android.com/studio/build/multidex
Updating the minSdkVersion to 22 in the app level build.gradle worked on its own.
There was no need for me to enter the multiDexEnabled settings noted above.
type multiDexEnabled true after minSdkVersion 21 in build.gradle app module
I downloaded Android Studio 4.0 (canary channel) and I'm trying to create a motion layout but the editor is greyed out, an error that usually means there's something wrong with the dependencies. I have updated all the relevant ones I could think of (as seen below), and I've rebuilt the project (also done invalidating caches and restart), but the problem persists. What am I missing?
build.gradle (app):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.android.aboutme"
minSdkVersion 19
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.60-eap-25"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
build.gradle (project):
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-alpha01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60-eap-25"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- activity_main.xml -->
<androidx.constraintlayout.motion.widget.MotionLayout
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:id="#+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="#xml/so_scene"
tools:showPaths="true">
<View
android:id="#+id/button"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#color/colorAccent"
android:text="Button" />
</androidx.constraintlayout.motion.widget.MotionLayout>
Try to delete app/build/ directory and rebuild project then.
I had a problem like you describe though the issue was not with dependencies, but with MotionLayout class initialization in Motion Editor. You may check messages by clicking icon at the top right of Motion Editor (icon might be "info" or "warning"), like here:
I can't reproduce the error I had, but it was about missing attribute motion_base in MotionScene initialization. Removing the app/build/ dir and getting it regenerated solved the issue.
I just created a new project on Android Studio 3.3 Canary 3 with Kotlin enabled. Then I also enabled data binding, but I'm getting an error saying that it could not find the DataBindingComponent class.
Here is my gradle file
buildscript {
apply from: 'versions.gradle'
addRepos(repositories)
dependencies {
classpath deps.android_gradle_plugin
classpath deps.kotlin.plugin
classpath deps.kotlin.allopen
classpath deps.navigation.safe_args_plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
repositories {
google()
}
}
allprojects {
addRepos(repositories)
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My module gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
android {
compileSdkVersion build_versions.target_sdk
buildToolsVersion build_versions.build_tools
defaultConfig {
applicationId "arca.advanced.mg.com.myapplication"
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
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
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation deps.support.app_compat
implementation deps.support.recyclerview
implementation deps.support.cardview
implementation deps.support.design
implementation deps.support.legacy
implementation deps.navigation.fragment_ktx
implementation deps.room.runtime
implementation deps.lifecycle.runtime
implementation deps.lifecycle.extensions
implementation deps.lifecycle.java8
implementation deps.retrofit.runtime
implementation deps.retrofit.gson
implementation deps.glide.runtime
implementation deps.dagger.runtime
implementation deps.dagger.android
implementation deps.dagger.android_support
implementation deps.constraint_layout
implementation deps.kotlin.stdlib
implementation deps.timber
implementation deps.rx.java
implementation deps.rx.android
kapt deps.dagger.android_support_compiler
kapt deps.dagger.compiler
kapt deps.room.compiler
kapt deps.lifecycle.compiler
}
my fragment file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="viewModel"
type="arca.advanced.mg.com.arca.ui.splash.SplashViewModel" />
</data>
<RelativeLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:src="#mipmap/ic_launcher" />
</RelativeLayout>
</layout>
and here is my error
I think it's kapt conflict.
Try to turn off Dagger if it's possible and check errors from Room like this:
Fields annotated with #Relation cannot be constructor parameters. These values are fetched after the object is constructed.
Cannot find setter for field.
Cannot figure out how to save this field into database.
If it will not help, try to turn off libs with kapt's one by one and check the error log carefully.
Check with ./gradlew app:dependencies transitive dependencies, maybe problems with androidx.
Also check gradlew app:dependencies --configuration kapt maybe you will find something suspicious
top build.gradle is as:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: 'versions.gradle'
repositories {
jcenter()
}
dependencies {
// Update checkable at https://jcenter.bintray.com/com/android/tools/build/gradle/
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle is as:
apply plugin: 'com.android.application'
android {
//compileSdkVersion "$rootProject.compileSdkVersion"
buildToolsVersion "$rootProject.buildToolsVersion"
// compileSdkVersion 23
compileSdkVersion "Google Inc.:Google APIs:23"
defaultConfig {
applicationId "nl.sogeti.android.gpstracker"
testApplicationId "nl.sogeti.android.gpstracker.tests"
minSdkVersion 15
targetSdkVersion 15
versionCode 1540
versionName "1.5.4"
buildConfigField "int", "BUILD_NUMBER", System.getenv("BUILD_NUMBER") as String ?: "0"
buildConfigField "String", "GIT_COMMIT", "\"" + System.getenv("GIT_COMMIT") + "\"" as String ?: "\"Unknown\""
generatedDensities = ["hdpi", "xxhdpi"]
archivesBaseName = "opengpstracker-$versionName"
}
if (rootProject.file("keystore.properties").exists()) {
apply from: 'signing.gradle'
}
buildTypes {
debug {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:preference-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
compile "com.jakewharton.timber:timber:$rootProject.timberVersion"
// compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.android.gms:play-services-base:7.3.0'
compile 'com.google.android.gms:play-services-location:7.3.0'
compile 'com.google.maps:google-maps-services:0.1.3'
// compile 'com.android.support:appcompat-v7:23.1.0'
compile project(':service')
testCompile "junit:junit:$rootProject.junitVersion"
}
map.xml is as:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mapScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--android:apiKey="0bmdf4-ggC50QWBY1OgGRutQ9bIboIy11OczZbw" -->
<com.google.android.maps.MapView
android:id="#+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/support_actionbar"
android:apiKey="0bmdf4-ggC50QWBY1OgGRutQ9bIboIy11OczZbw"
android:clickable="true"
android:enabled="true"
android:visibility="visible" />
<TextView
android:id="#+id/currentSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/support_actionbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textColor="#ff000000"
android:textSize="12pt"
android:textStyle="bold"
android:visibility="gone" />
before adding to compileSdkVersion "Google Inc.:Google APIs:23" google map is drawn in proper way. Because of as build it with Android Studio 2.1, it require to compileSdkVersion "Google Inc.:Google APIs:23" and after its not showing map.
Any one please suggest, what will i do for that to show google map
Google Maps v1 is deprecated, maybe that's why it's not working. It is stated here that:
Note: Version 1 of the Google Maps Android API has been officially
deprecated as of December 3rd, 2012. This means that from March 18th,
2013 you will no longer be able to request an API key for this
version. No new features will be added to Google Maps Android API v1.
However, apps using v1 will continue to work on devices. Existing and
new developers are encouraged to use Google Maps Android API v2.
Although v1 will continue to work on device, no new features will be added to it and the support on it will not be entertained. Maybe that is also the reason why you cannot upgrade it to SDK Version 23. So I suggest you to update your code/project.
For more information about the v1, check this link.