Project Gradle sync keeps failing. (Gradle DSL method not found) - java

beginner android developer so not a lot of experience on how the gradle works, I've tried looking at other examples but I still cant get my problem. Basically, I've just downloaded one of the sample projects from google android developer examples, and cant successfully build the project. I keep getting: Gradle sync failed: Gradle DSL method not found: 'compile()'
The app gradle is:
apply plugin: 'com.android.application'
android {
enforceUniquePackageName = false
compileSdkVersion android_compile_version
buildToolsVersion android_version
defaultConfig {
minSdkVersion android_min_sdk_version
targetSdkVersion android_compile_version
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile project(':libraries:BaseGameUtils')
compile 'com.google.android.gms:play-services:4.3.23'
}
buildscript {
repositories {
jcenter()
}
}
and as for the project gradle:
// this is the parent build configuration for all the sample projects.
// for more information on gradle build files when used in a multi-project build, see
// http://gradle.org/docs/current/userguide/multi_project_builds.html
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
// allprojects apply to every project
allprojects {
repositories {
jcenter()
}
ext {
android_compile_version = 23
android_version = '23.0.1'
android_min_sdk_version = 9
appcompat_library_version = '23.0.1'
support_library_version = '23.0.1'
gms_library_version = '8.1.0'
}
}

Related

android studio: FAILURE: Build failed with an exception

I am trying to build a flutter app I get so many problems while building it and found a solutions for all of them but now I am stuck since the morning with this one:
> Task :firebase_auth:generateDebugRFile FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_auth:generateDebugRFile'.
> Could not resolve all files for configuration ':firebase_auth:debugCompileClasspath'.
> Could not find browser-1.0.0.aar (androidx.browser:browser:1.0.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/browser/browser/1.0.0/browser-1.0.0.aar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 37s
my project build.gradle:
buildscript {
ext.kotlin_version = '1.5.31'
repositories {
google()
jcenter()
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.75'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
my app build.gradle:
buildscript {
repositories {
// ...
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
// ...
// OneSignal-Gradle-Plugin
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
applicationId "com.inspireui.fluxstore"
minSdkVersion 20
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
resConfigs "en"
manifestPlaceholders = [
onesignal_app_id: 'PUT_YOUR_ONESIGNAL_APP_ID_HERE',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.browser:browser:1.3.0'
// For checking GMS availability.
implementation "com.google.android.gms:play-services-base:17.6.0"
// Fix duplicate exoplayer
implementation 'com.google.android.exoplayer:exoplayer:2.14.1'
}
googleServices { disableVersionCheck = true }
//Fix android-r issue
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
afterEvaluate {project ->
if (project.hasProperty("android") && project.property("android").compileSdkVersion.equals("android-R")) {
android {
compileSdkVersion 30
}
}
}
}
gradle.propertis:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
Solutions I tried:
invalidate cache and restart
flutter clean && flutter pub get
gradlew clean && gradlew build
delete the %USER%/.android and %USER%/.gradle and delete every thing related to android studio and reinstalled it
use a VPN ( tried 3 )
but unfortunatly, nothing helped me
for further info: I am building fluxstore app
I still think its a connection issue . is maven google available in your browser with no VPN ?
if no then here is a old solution of mine , on how to configure gradle to use you VPN properly . Because you need to tell gradle to send request over VPN using gradle.properties file .

error: undefined reference to 'libiconv_close' in Ndk Android Studio

Iam getting error on setting up my ndk for gstreamer library in android studio.
Below is the error which iam getting-:
cerbero.git/1.16/build/sources/android_universal/armv7/glib-2.56.1/_builddir/../glib/gconvert.c:308: error: undefined reference to 'libiconv_close'
My project level gradle is -:
> buildscript {
> repositories {
> jcenter()
> google()
> }
> dependencies {
> classpath 'com.android.tools.build:gradle:3.5.0'
> } }
>
> allprojects {
> repositories {
> jcenter()
> google()
> } }
and my app.gradle is -:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "org.freedesktop.gstreamer.tutorials.tutorial_2"
minSdkVersion 9
targetSdkVersion 26
ndk {
moduleName "tutorial-2"
abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path '../../gstreamer-tutorial2/app/src/main/jni/Android.mk'
}
}
}
Refrences which iam using is from-:
Gstreamer examples in Android Studio
Also can anybody help with good references for implemeting gstream library in android studio
Thanks
Try to add libiconv to your Android.mk file
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_NET) x264 openh264 videoparsersbad mulaw
G_IO_MODULES := gnutls
GSTREAMER_EXTRA_LIBS := -liconv #This is what you need
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

Android Studio failed for task ':app:compileDefaultFlavorDebugJavaWithJavac

I am using the android studio version 3.1. I am working with youtube Api project. and had added some dependency in the gradle. After sysc it's shows everything oke and fresh. but when i go to run the application it show the error below. I have changed the compileSdkVersion and tried other ways to fix that.
Thanks in advance.
Error
org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:compileDefaultFlavorDebugJavaWithJavac'.
Build.grable
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 25
defaultConfig {
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
flavorDimensions "default"
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation 'com.android.support:cardview-v7:25.2.0'
implementation 'com.android.support:recyclerview-v7:25.2.0'
implementation 'com.android.support:appcompat-v7:25.2.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.apis:google-api-services-youtube:v3-rev182-1.22.0'
implementation 'com.google.http-client:google-http-client-android:1.20.0'
implementation 'com.google.api-client:google-api-client-android:1.20.0'
implementation 'com.google.api-client:google-api-client-gson:1.20.0'
implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.0'
}
Try this code (app level grandle):
buildscript {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
jcenter()
google()
}
}
And project level grandle:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
flavorDimensions "default"
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.apis:google-api-services-youtube:v3-rev182-1.22.0'
implementation 'com.google.http-client:google-http-client-android:1.20.0'
implementation 'com.google.api-client:google-api-client-android:1.20.0'
implementation 'com.google.api-client:google-api-client-gson:1.20.0'
implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.0'
}
Have you tried restarting android studio? or have you try cleaning / re-build the project? And pls also try to go to file -> invalidate caches / restart and then press that and press invalidate caches and restart.
I just found that there are bugs like this in Android Studio 3.1, pls try follow this link

DuplicateFileException in apk build using Kotlin

I am trying to build a basic app using Kotlin/Anko but I am getting the following duplicate file exception
Execution failed for task
':app:transformResourcesWithMergeJavaResForDebug'.>
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException: Duplicate files
copied in APK kotlin/internal/internal.kotlin_builtins File1:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-runtime\1.0.6.\3562c66f648480d3bd4f76cff722488ced13445b\kotlin-runtime-1.0.6.jar File2:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.0.6\4008eb91a337b377dae7e4572b8b543e5321f549\kotlin-compiler-embeddable-1.0.6.jar
Following is the code for the app level gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kotlin.androdikotlinexample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//kotlin
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//anko
compile "org.jetbrains.anko:anko-design:0.8.3"
compile "org.jetbrains.anko:anko-support-v4:0.8.3"
compile "org.jetbrains.anko:anko-sdk15:0.8.3"
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.3'
}
Following is the code for Project level gradle file:
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
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 {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the basic code for the MainUI file
class MainUI : AnkoComponent<MainActivityKotlin> {
override fun createView(ui: AnkoContext<MainActivityKotlin>): View = with(ui) {
coordinatorLayout {
verticalLayout {
// maybe put some content here
}
floatingActionButton {
imageResource = android.R.drawable.ic_menu_edit
onClick {
ui.owner.startActivityForResult<MainActivityKotlin>(1)
}
}.lparams {
gravity = Gravity.BOTTOM or Gravity.END
}
}
}
}
And the content is set on MainActivityKotlin file using the method MainUI().setContentView(this) in its onCreatemethod.
I have tried deleting the gradle cache and building the project again but nothing works. Please let me know where am I going wrong?
Remove compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" from your gradle
Remove also all buildscript section from you app level gradle
Try this one:
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile ("org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version") {
transitive = false
}
Also you don't need the android-extensions dependency anymore, as it's bundled into the plugin. Just having the apply plugin: 'kotlin-android-extensions' in your gradle is enough.

Error: java.util.zip.ZipException: duplicate entry fails on building

The error i got is:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqr.class
I have been stuck for hours on this issue.
Here is my Build.Gradle (app file) .
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
buildscript {
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "org.my.app"
minSdkVersion 19
targetSdkVersion 23
versionCode 140
versionName "1.4.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:7.0.0'
// Android SDK
compile 'com.facebook.android:facebook-android-sdk:4.+'
// Audience Network SDK. Only versions 4.6.0 and above are available
compile 'com.facebook.android:audience-network-sdk:4.+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.facebook.fresco:fresco:0.9.0+'
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2#aar') {
transitive = true;
}
}
crashlytics {
enableNdk true
androidNdkOut 'src/main/obj'
androidNdkLibsOut 'src/main/libs'
}
You are adding the same class with different versions twice.
You are using the Google play services modules with different releases:
Use:
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'

Categories

Resources