Gradle 同步失败:构建文件“...\build.gradle”不应包含包语句
Gradle sync failed: Build file '...\build.gradle' should not contain a package statement
我的应用程序运行得非常好,我不知道突然之间发生了什么 build.gradle 抛出错误 Gradle 同步失败,构建文件 '...\build.gradle' 不应该包含包声明,问题是我也检查了我的其他应用程序,它们有相同的包 com.example.myapplication;
这是我的 build.gradle(project:FaceRec);
package com.example.myapplication;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.E;
这是应用程序中的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 21
targetSdkVersion 28
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.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':openCVLibrary347')
dependencies {
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}
}
如果需要任何进一步的说明,请告诉我。
非常感谢您。
参考这个Android Studio java file gets corrupted
只需删除您的缓存即可基本解决您的问题。
C:\Users\cc.AndroidStudio3.2\system\caches
感谢 L2_Paver 的指导。我注意到 build.gradle(project:FaceRec) 的内容没有意义,我不知道它在哪里以及如何出现,所以我更改了整个代码并粘贴了一个空项目的 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.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
}
我的应用程序运行得非常好,我不知道突然之间发生了什么 build.gradle 抛出错误 Gradle 同步失败,构建文件 '...\build.gradle' 不应该包含包声明,问题是我也检查了我的其他应用程序,它们有相同的包 com.example.myapplication;
这是我的 build.gradle(project:FaceRec);
package com.example.myapplication;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.E;
这是应用程序中的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 21
targetSdkVersion 28
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.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':openCVLibrary347')
dependencies {
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}
}
如果需要任何进一步的说明,请告诉我。
非常感谢您。
参考这个Android Studio java file gets corrupted
只需删除您的缓存即可基本解决您的问题。
C:\Users\cc.AndroidStudio3.2\system\caches
感谢 L2_Paver 的指导。我注意到 build.gradle(project:FaceRec) 的内容没有意义,我不知道它在哪里以及如何出现,所以我更改了整个代码并粘贴了一个空项目的 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.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
}