Gradle同步失败:构建文件'... \ build.gradle'不应包含package语句 [英] Gradle sync failed: Build file '...\build.gradle' should not contain a package statement
问题描述
我的应用程序运行正常,我不知道突然发生了什么build.gradle引发错误,指示Gradle同步失败,构建文件'... \ build.gradle'不应包含package语句,事情是我也检查了其他应用程序,并且它们具有相同的包com.example.myapplication;
My application was working perfectly fine, I dont know what happened all of a sudden the build.gradle throw an error stating Gradle sync failed, build file '...\build.gradle' should not contain a package statement, the thing is I checked my other apps as well and they had the same package com.example.myapplication;
这是我的build.gradle(project:FaceRec);
here is my 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
and here is the build.gradle with in the app
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.+'
}
}
如果需要进一步澄清,请告诉我.
if any further clarification is needed please let me know.
非常感谢您.
推荐答案
感谢L2_Paver的指导.我注意到build.gradle(project:FaceRec)的内容没有意义,我不知道它的位置和方式,因此我更改了整个代码并粘贴了一个空项目的gradle并添加了一些引用,现在,使用下面的替换代码,该应用程序开始正常运行.
Thanks L2_Paver for the guide. I noticed that the build.gradle(project:FaceRec) is having contents that does not make sense, I dont know where and how it was there, so I changed the whole code and pasted an empty project's gradle and added some of the references, now with the replaced code as below the application started to work fine.
// 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
}
这篇关于Gradle同步失败:构建文件'... \ build.gradle'不应包含package语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!