Je reçois cette erreur dans Android après la mise à jour du studio Android 3.0 à 3.1 et Gradle de 3.1 à 4.4.
Comment puis-je le réparer?
Cela fonctionne correctement avec Gradle 3.1 et Android studio 3.0.
Comment puis-je le faire fonctionner?
Application Gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.Android.application'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
google()
maven { url 'https://maven.fabric.io/public' }
}
Android {
compileSdkVersion 27
dataBinding {
enabled = true
}
defaultConfig {
applicationId "com.example.example"
minSdkVersion 22
targetSdkVersion 23
versionCode 13
versionName "1.13"
testInstrumentationRunner "Android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-Android.txt'), 'proguard-rules.pro'
}
}
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'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.Android.support:appcompat-v7:27.0.2'
implementation 'com.Android.support.constraint:constraint-layout:1.0.2'
implementation 'com.Android.support:design:27.0.2'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-crash:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.Android.support.test:runner:1.0.1'
androidTestImplementation 'com.Android.support.test.espresso:espresso-core:3.0.1'
compile 'com.amazonaws:aws-Android-sdk-cognitoidentityprovider:2.6.8'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.amazonaws:aws-Android-sdk-core:2.6.8'
compile 'com.amazonaws:aws-Android-sdk-s3:2.6.8'
compile 'com.amazonaws:aws-Android-sdk-ddb:2.6.8'
compile 'com.github.twinkle942910:monthyearpicker:0.0.1'
compile('com.crashlytics.sdk.Android:crashlytics:2.9.0@aar') {
transitive = true;
}
compile 'com.google.Android.gms:play-services-location:11.8.0'
compile 'com.zsoltsafrany:needle:1.0.0'
implementation 'com.Android.support:cardview-v7:27.0.2'
compile 'com.white:progressview:1.0.1'
compile 'br.com.simplepass:loading-button-Android:1.8.1'
implementation files('/libs/Android-sdk-0.1.0.jar')
compile 'com.Android.support:support-v4:27.0.2'
compile 'com.clevertap.Android:clevertap-Android-sdk:3.1.8'
compile 'testfairy:testfairy-Android-sdk:1.+@aar'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}
apply plugin: 'com.google.gms.google-services'
Gradle-Project:
// 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.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle-wrapper.Properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.Zip
Gradle.properties
org.gradle.jvmargs=-Xmx1536m
Android.databinding.enableV2=true
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"
xmlns:tools="http://schemas.Android.com/tools">
<Android.support.constraint.ConstraintLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:background="@color/white"
Android:padding="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Class_application_MyClass1"
tools:showIn="@layout/activity_class_application_myclass_1">
<ScrollView
Android:id="@+id/scrollView2"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_marginBottom="60dip"
Android:layout_marginTop="20dip"
Android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Android.support.v7.widget.CardView
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:focusableInTouchMode="true"
Android:orientation="vertical"
Android:padding="25dp">
<Android.support.design.widget.TextInputLayout
Android:id="@+id/name_TextInputLayout"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginBottom="25dp">
<Android.support.design.widget.TextInputEditText
Android:id="@+id/name"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawablePadding="10dp"
Android:hint="Name"
Android:imeOptions="actionNext"
Android:singleLine="true"
Android:text=""
Android:textSize="13sp" />
</Android.support.design.widget.TextInputLayout>
<Android.support.design.widget.TextInputLayout
Android:id="@+id/number_TextInputLayout"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_marginBottom="25dp">
<Android.support.design.widget.TextInputEditText
Android:id="@+id/number"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawablePadding="10dp"
Android:hint="number"
Android:inputType="textCapCharacters"
Android:maxLength="10"
Android:text=""
Android:textAllCaps="true"
Android:textSize="13sp" />
</Android.support.design.widget.TextInputLayout>
<Android.support.design.widget.TextInputLayout
Android:id="@+id/classnumber_TextInputLayout"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginBottom="25dp">
<Android.support.design.widget.TextInputEditText
Android:id="@+id/class_number"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawablePadding="10dp"
Android:hint="class"
Android:imeOptions="actionNext"
Android:inputType="textCapCharacters"
Android:maxLength="15"
Android:singleLine="true"
Android:text=""
Android:textSize="12sp" />
</Android.support.design.widget.TextInputLayout>
</LinearLayout>
</Android.support.v7.widget.CardView>
</ScrollView>
</Android.support.constraint.ConstraintLayout>
</layout>
Activity.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">
<Android.support.design.widget.CoordinatorLayout
Android:id="@+id/top_layout"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
tools:context=".Class_application_MyClass1">
<Android.support.design.widget.AppBarLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:theme="@style/AppTheme.AppBarOverlay">
<Android.support.v7.widget.Toolbar
Android:id="@+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="?attr/actionBarSize"
Android:background="@color/fundscorner_blue"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<Android.support.constraint.ConstraintLayout
Android:id="@+id/linearLayout3"
Android:layout_width="fill_parent"
Android:layout_height="20dp"
Android:background="@color/white"
app:layout_anchor="@+id/content_class_application_myclass_1"
app:layout_anchorGravity="top|center">
<com.white.progressview.HorizontalProgressView
Android:id="@+id/progress100"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:padding="10dp"
Android:progress="25"
app:progressReachColor="@color/colorPrimary"
app:progressTextColor="@color/colorPrimary"
app:progressTextVisible="false"
Android:minHeight="20dip"
Android:maxHeight="20dip"
/>
</Android.support.constraint.ConstraintLayout>
</Android.support.design.widget.AppBarLayout>
<include
Android:id="@+id/content_class_application_myclass_1"
layout="@layout/content_class_application_myclass_1"/>
<LinearLayout
app:layout_anchor="@+id/content_class_application_myclass_1"
app:layout_anchorGravity="bottom|center"
Android:layout_width="match_parent"
Android:layout_height="wrap_content">
<Button
Android:background="@drawable/ripple"
style="?borderlessButtonStyle"
Android:id="@+id/button_stage1"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:backgroundTint="@color/fundscorner_blue"
Android:text="Next"
Android:textColor="@color/white"
/>
</LinearLayout>
</Android.support.design.widget.CoordinatorLayout>
</layout>
En fichier Java:
ActivityClassApplicationMyClass1Binding binding;
binding = DataBindingUtil.setContentView(this, R.layout.activity_class_application_myclass_1);
binding.name.settext("Name");
C'est à cause de votre nom de classe ou nom de package qui utilise la liaison de données. Ces classes (qui utilisent la liaison de données) doivent commencer par Word majuscule et les packages commencent par des minuscules.
Comme Mehdi l'a déjà indiqué dans sa réponse, la raison de cette erreur est la mise en majuscule dans le nom du package Java des classes de liaison et de variable.
En examinant plus en détail les journaux, vous constaterez que l'erreur est renvoyée à ClassName.bestGuess (String) . La raison en est que le nom du package de vos classes liées, c'est-à-dire celles du champ <variable>
de votre présentation, contient des caractères majuscules dans leur nom. Cela empêche la méthode de séparer le nom de classe du nom de package et génère une erreur.
[pour être honnête, c’est un comportement plutôt médiocre, mais il n’ya probablement pas de meilleur moyen (encore)]
Il en va de même pour la classe de liaison générée, elle doit également figurer dans un package ne contenant aucune lettre majuscule. Comme il utilise par défaut le nom de votre package d'application, vous devez modifier le nom du package Java en ajoutant la propriété class
au champ <data>
de votre présentation ( Pour en savoir plus, cliquez ici ).
Exemple:
<layout xmlns:app="http://schemas.Android.com/apk/res-auto">
<data class="com.example.ExampleDataBinding">
<variable
name="example"
type="com.example.ExampleClass" />
</data>
</layout>
Le nom de la classe Binding semble être faux. Pouvez-vous essayer de le changer de ActivityClassApplicationMyClass1Binding
à ActivityClassApplicationMyclass1Binding