Android studioを3.0から3.1、Gradleを3.1から4.4に更新した後、Androidでこのエラーが発生します。
どうすれば修正できますか?
Gradle 3.1およびAndroid studio 3.0で正常に動作しています。
どうすれば機能しますか?
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>
In Java file:
ActivityClassApplicationMyClass1Binding binding;
binding = DataBindingUtil.setContentView(this, R.layout.activity_class_application_myclass_1);
binding.name.settext("Name");
その理由は、データバインディングを使用するクラス名またはパッケージ名です。これらのクラス(データバインディングを使用)は大文字のWordで始まり、パッケージは小文字で始まります。
このエラーの理由は、Mehdiが答えですでに述べたように、バインディングクラスと変数クラスのJavaパッケージ名の大文字化です。
さらにログを調べると、 ClassName.bestGuess(String) でエラーがスローされることがわかります。理由は、バインドされたクラスのパッケージ名(別名、レイアウトの<variable>
フィールドのパッケージ名)のパッケージ名に大文字が含まれているためです。これにより、メソッドはクラス名とパッケージ名を区別できなくなり、エラーがスローされます。
[正直に言うと、これはやや悪い振る舞いですが、おそらくまだ良い方法はありません(まだ)]
生成されたバインディングクラスについても同じことが言えます。また、大文字を含まないパッケージに含める必要があります。デフォルトでアプリのパッケージ名を使用するため、レイアウトの<data>
フィールドにclass
プロパティを追加して、Javaパッケージ名を変更する必要があります(- 詳細はこちら )。
例:
<layout xmlns:app="http://schemas.Android.com/apk/res-auto">
<data class="com.example.ExampleDataBinding">
<variable
name="example"
type="com.example.ExampleClass" />
</data>
</layout>
Bindingクラス名が間違っているようです。 ActivityClassApplicationMyClass1Binding
からActivityClassApplicationMyclass1Binding
に変更してみてください
他の人が示唆したように、パッケージ名は小文字で始める必要があります。私の問題は、アンダースコア「_」で始まりましたが、これも許可されていません。