Gradle sync failed: Build file '...\build.gradle' should not contain a package statement - android-studio

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;
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;
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.
Thanks you very much in advance.

refer to this Android Studio java file gets corrupted
Simply delete your caches should mostly solve your problem.
C:\Users\cc.AndroidStudio3.2\system\caches

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
}

Related

Android studio can't find dependencies android-gif-drawable

i'm trying to import this android-gif-drawable to my project, but even if i did set the emplementation and settings, i can't import or use it.
Here my build.graddle(:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.androidapp"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
implementation 'com.squareup.picasso:picasso:2.8'
}
And my settings.gradle(AndroidApp)
import org.gradle.api.initialization.resolve.RepositoriesMode
pluginManagement {
repositories {
gradlePluginPortal()
google()
//jcenter()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
//jcenter()
mavenCentral()
//maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
// maven { url 'https://jitpack.io' }
}
}
rootProject.name = "AndroidApp"
include ':app'
But everytime i try to import it or use it i got errors:
import pl.droidsonroids.gif.GifImageView; -> Unresolved reference: pl
<pl.droidsonroids.gif.GifImageView -> Cannot resolve class pl.droidsonroids.gif.GifImageView
I tried to set as specified on the coral page with the "buildscript" before the "plugins" and "allproject" after, but of course i have the error:
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'app\build.gradle'
I can't find a way to make it work or at least see if the library is correctly loaded (but since i don't have an error for the dependency as some other posts, i imagine it found it).
Hum...ok so its's working now...
while it wasn't working i restarted android studio, closed the app, clean and rebuilded the project many time, and it was still not working.
I sleeped, restarted to work ( android wasn't closed) and it worked.. I suposed it was stil loading yesterday when i tried? honnestly i dont get it.
hope this will help someone in the same situation

After my Android Studio was upgraded to Arctic Fox version, then can't run emulator correctly in this project, why?

After my Android Studio was upgraded to Arctic Fox version, then can't run emulator correctly in this project, why?
build.gradle(Module)
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id "androidx.navigation.safeargs.kotlin" }
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.squall.doodlekong_android"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
} }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
//Scarlet
def scarletVersion = '0.1.12'
implementation "com.tinder.scarlet:scarlet:$scarletVersion"
implementation "com.tinder.scarlet:websocket-okhttp:$scarletVersion"
implementation "com.tinder.scarlet:lifecycle-android:$scarletVersion"
implementation "com.tinder.scarlet:message-adapter-gson:$scarletVersion"
implementation "com.tinder.scarlet:stream-adapter-coroutines:$scarletVersion"
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//okhttp3
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
//Easy Permissions
implementation 'pub.devrel:easypermissions:3.0.0'
//Preferences DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0-rc02"
implementation "androidx.datastore:datastore-preferences-core:1.0.0-rc02"
//Dagger Hilt
implementation 'com.google.dagger:hilt-android:2.38.1'
kapt 'com.google.dagger:hilt-compiler:2.38.1'
//Timber
implementation 'com.jakewharton.timber:timber:4.7.1'
def lifecycle_version = "2.4.0-alpha02"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
//Coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
// Navigation component
def nav_version = "2.3.5"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
//Gson
implementation 'com.google.code.gson:gson:2.8.7'
//Lottie
implementation 'com.airbnb.android:lottie:4.0.0' }
build.gradle(Project)
buildscript {
ext.kotlin_version = "1.5.21"
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} }
allprojects {
repositories {
google()
mavenCentral()
jcenter()
} }
task clean(type: Delete) {
delete rootProject.buildDir }
build error:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has
been replaced with 'VariantProperties.applicationId'. It will be
removed in version 7.0 of the Android Gradle plugin. For more
information, see TBD. To determine what is calling
BaseVariant.getApplicationIdTextResource, use
-Pandroid.debug.obsoleteApi=true on the command line to display more information.
I think if you inspect code with lint you will find the solution.
On Windows: gradlew :app:lint
On Linux/Mac: ./gradlew :app:lint
But, i think this error is causing because with Artic Fox new version require another call of arguments... search for call arguments in your code and change to "require_()" signature... for example, in kotlin: in place of "aguments!!", call "requireArguments()"
Hope i help you!

Android Studio GridLayout not working. Shows completely grey into Design View

I hope someone can help me with this :S
I am working on Android Studio 3.6.2 and Gradle version is 5.6.4.
I just tried to drag and drop a GridLayout into a ConstraintLayout. But for some reason the GridLayout shows completely grey.
I read in my research that could be something related with the Gradle files. I read I need:
1) implementation 'androidx.gridlayout:gridlayout:1.0.0'
2)
repositories {
google()
}
I have these two included in my Gradle files. So, am I missing something somewhere?
I upload a reference image and some code. Thanks in advance ;)
Design View
build.gradle (Project: AndroidSample)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.aretius.androidsample"
minSdkVersion 26
targetSdkVersion 29
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"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
}
build.gradle (Module: app)
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
Well, I finally solved my problem reinstalling Android Studio with the latest version of it :)

Cannot resolve android annotation for sharedPreferences

I imported this project from eclipse. everything is sorted out but there is this one issue I'm stuck with.
I've a sharedPreference interface which is done using annotations
import com.googlecode.androidannotations.annotations.sharedpreferences.DefaultBoolean;
import com.googlecode.androidannotations.annotations.sharedpreferences.DefaultString;
import org.androidannotations.annotations.sharedpreferences.SharedPref;
#SharedPref
public interface RememberMePrefs {
#DefaultString("")
String email();
#DefaultString("")
String password();
#DefaultBoolean(true)
boolean enabled();
}
when I try to use this interface like this :
#Pref
RememberMePrefs_ rememberMePrefs;
it says "Cannot resolve symbol RememberMePrefs_"
this is my Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "xxxxxx"
minSdkVersion 16
targetSdkVersion 29
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
def AAVersion = '4.6.0'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
apt "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation files('libs/android-support-v4.jar')
implementation files('libs/androidannotations-api-2.7.1.jar')
implementation files('libs/gson-2.2.2.jar')
implementation files('libs/saripaar-11242012.jar')
implementation files('libs/spring-android-core-1.0.1.RELEASE.jar')
implementation files('libs/spring-android-rest-template-1.0.1.RELEASE.jar')
implementation files('libs/actionbarsherlock.jar')
}
Any help will be appriciated as I've never worked on annotations before.
You are using the latest AndroidAnnotations library in your build.gradle, but importing the old namespace in your Java code.
You should import:
import org.androidannotations.annotations.sharedpreferences.DefaultBoolean;
import org.androidannotations.annotations.sharedpreferences.DefaultString;
import org.androidannotations.annotations.sharedpreferences.SharedPref;
This should be done in other classes as well, probably.

lombok fails when compile with Gradle 4.5 in Android Studio 3.1.2

I want to use lombok in my Android Studio project.
My current build.gradle project file looks like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And my app build.gradle file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "app.getter.android"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
customDebugType {
debuggable true
}
}
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.16.20'
annotationProcessor 'org.projectlombok:lombok:1.16.20'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.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'
}
I've already installed Lombok Plugin in my Android Studio 3.1.2 and all seems correct. All the lombok tools are available tu use it. The content assist shows all lombok dependencies and there isn't compilation errors in my workspace. However when I try to run a test, Gradle compiles my code and it can't find the lombok generated code like getters/setters or val variables are not transformed to my Java type so it seems that annotationProcessor is not invoked before the compilation or the generated code by the annotationProcessor isn't in the classpath when gradle makes the compilation.
I've tried to use gradle-lombok-plugin but nothing works for me. What I'm doing wrong?

Resources