ClassNotFoundException:未找到 class "androidx.support.constraint.ConstraintLayout" - api 28
ClassNotFoundException: Didn't find class "androidx.support.constraint.ConstraintLayout" - api 28
我对 Gradle 文件做了一些更改,当我尝试 运行 应用程序时,我收到此错误:java.lang.ClassNotFoundException:没有找到 class "androidx.support.constraint.ConstraintLayout"
------------XML------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
android:configChanges = "orientation|keyboardHidden"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="607dp"
android:layout_height="313dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />
</android.support.constraint.ConstraintLayout>
------------Gradle 应用程序--------
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.eladk.flagged"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-ads:18.1.1'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.5.1"
}
apply plugin: 'com.google.gms.google-services'
----------------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.4.2'
classpath 'com.google.gms:google-services:4.2.0'
// 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
}
----------------Activity-----------------
package com.example.eladk.flagged;
import android.content.Intent;
import android.os.Handler;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private int waitTime = 2500;
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageView);
Animation Animation = AnimationUtils.loadAnimation(this, R.anim.transition);
imageView.startAnimation(Animation);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(".SecondActivity");
startActivity(intent);
您应该将您的项目迁移到 AndroidX,
ConstraintLayout
的示例
implementation "androidx.constraintlayout:constraintlayout:$constraintLayout_version"
我对 Gradle 文件做了一些更改,当我尝试 运行 应用程序时,我收到此错误:java.lang.ClassNotFoundException:没有找到 class "androidx.support.constraint.ConstraintLayout"
------------XML------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
android:configChanges = "orientation|keyboardHidden"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="607dp"
android:layout_height="313dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />
</android.support.constraint.ConstraintLayout>
------------Gradle 应用程序--------
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.eladk.flagged"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-ads:18.1.1'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.5.1"
}
apply plugin: 'com.google.gms.google-services'
----------------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.4.2'
classpath 'com.google.gms:google-services:4.2.0'
// 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
}
----------------Activity-----------------
package com.example.eladk.flagged;
import android.content.Intent;
import android.os.Handler;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private int waitTime = 2500;
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageView);
Animation Animation = AnimationUtils.loadAnimation(this, R.anim.transition);
imageView.startAnimation(Animation);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(".SecondActivity");
startActivity(intent);
您应该将您的项目迁移到 AndroidX,
ConstraintLayout
implementation "androidx.constraintlayout:constraintlayout:$constraintLayout_version"