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.
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'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)
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 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
I'm trying to use the Hugo library developed by Jake Wharton.
I added the statement:
compile 'com.jakewharton.hugo:hugo-plugin:1.2.1'
to my dependencies in my build.gradle file at the app level.
Then when I try to annotate with #DebugLog on my methods, it appears in red, as if the IDE doesn't recognize it.
I tried typing in an import statement like:
import com.jakewharton.hugo;
but the jakewharton part of the import statement appears in red, meaning it doesn't see it.
I've googled, and found references like:
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
I'm not sure what the difference between compile and classpath is.
Also, I see a reference to:
apply plugin: 'hugo'
Where should that go?
As you can see I'm totally lost. Any ideas on how to make this work is greatly appreaciated.
I'm not sure you are referencing the app module build.gradle or the project level build.gradle.
But eventually, I put it all in the app module build.grade and it worked for me. This is how the file looked like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.app_name"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
A correct configuration would look like this in your build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
dependencies {
// Other dependencies
}
There is no need to add Hugo to the second dependencies section, this is done for you by the plugin.
I had had the same problem, but realized I had apply plugin: 'com.android.application' typed twice. Once I deleted the extra reference, placing the Jake Wharton stuff at the top of build.gradle (app), it removed the red lines.