Gradle indentation issue in Android Studio 2.3 - android

Every time I create a new Activity in AS 2.3 it messes up the build.gradle indentation that results in errors like this.
Error:Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I have to redo the indentations every time. Any idea how to fix this permanently?

Don't use compile as a property and don't change the gradle structure.
compile 'com.android.support:appcompat-v7:22.2.1' compile
'com.parse:parse-android:1.11.0'
Sometimes Gradle build messes up the code like above, it still happens. Probably related to Java JDK updates.

The problem seems to be caused by the lines which contain curly braces like:
compile('com.github.tony19:logback-android-core:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
In order to avoid the bug just put all the lines with curly braces above the "usual" (i.e. compile 'something') lines like this:
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.github.tony19:logback-android-core:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
compile('com.github.tony19:logback-android-classic:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
compile 'com.bolyartech.forge.android:forge-android:6.1.0'
compile 'com.bolyartech.scram_sasl:scram_sasl:2.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup:otto:1.3.6'
compile 'com.google.code.gson:gson:2.7'
compile 'com.github.franmontiel:PersistentCookieJar:v0.9.3'
compile 'com.google.dagger:dagger:2.9'
...

Related

Getting gradle error with OneSignal in Android Studio

I am trying to incorporate OneSignal in my Android project. Getting following gradle error which saying Support libraries must have same version.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)'
testCompile 'junit:junit:4.12'
}
Gradle giving error on compile 'com.android.support:appcompat-v7:25.3.1' and compile 'com.google.android.gms:play-services-ads:10.2.4' .
You have to provide onesignal_app_id and onesignal_google_project_number values in your Android Manifest.
Attribute meta-data#onesignal_app_id#value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_app_id> is provided.
Attribute meta-data#onesignal_google_project_number#value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_google_project_number> is provided.
These are the actual reasons for the build failure. Not the libraries/dependencies that you have mentioned

Android libraries: versions conflict issue

I've the below dependence in my Android app build.gradle
compileSdkVersion 25
buildToolsVersion "25.0.2"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0'
compile 'com.google.firebase:firebase-appindexing:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
but getting an error about versions compatibility, as shown below, what is the one to be changed here, i could not figure it out :(
I had same problem what i did was compile the higher version of libraries ,which were creating this error,in app:gradle only.
for example in your case
compile 'com.android.support:mediarouter-v7:25.0.0'
Add this in app:gradle.
There may be more like this mediarouter libraries if it still give error add them jst like this(making them higher version).
First you need to find out where's what consists of a conflicting version of the library. The easiest way to do so is to:
Open Terminal pane in your Android Studio.
Type in: ./gradlew androidDependencies
Find the row that represents the ENCLOSING library consisting of a conflict.
Then just use exclude statement for the conflicting library, like so:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
(the example assuming com.android.support.test.espresso:espresso-core:2.2.2 was the ENCLOSING library, and com.android.support:support-annotations being the conflict)

Gradle dependency exclusion not working

My project build.gradle dependencies are:
dependencies {
...
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-appinvite:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'co.realtime:messaging-android:2.1.58'
}
And the co.realtime:messageing-android build.gradle dependencies are:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.android.support:appcompat-v7:21.0.3'){
transitive = true;
}
compile ('com.google.android.gms:play-services:6.1.71'){
transitive = true;
}
compile ('com.googlecode.json-simple:json-simple:1.1'){
transitive = true;
}
}
If I try to compile my project I get the following error:
Error:Gradle: Execution failed for task
':app-module:processProdDebugResources'.
Error: more than one library with package name 'com.google.android.gms' You can temporarily disable this error with
android.enforceUniquePackageName=false However, this is temporary
and will be enforced in 1.0
If I use enforceUniquePackageName(false) I get:
cannot resolve symbol to GoogleCloudMessaging.INSTANCE_ID_SCOPE
So I guess I'll have to solve this by managing the dependencies. I've tried:
compile ('co.realtime:messaging-android:2.1.58'){
exclude module: 'com.google'
}
compile ('co.realtime:messaging-android:2.1.58'){
exclude group: 'com.google.android.gms', module: 'play-services-gcm'
}
But nothing seams to work... How can I solve this?
Thanks.
The problem was in 'play-services-gcm' instead of 'play-services'
compile ('co.realtime:messaging-android:2.1.58'){
exclude group: 'com.google.android.gms', module: 'play-services'
}
grrr those typo mistakes... Well I thought I could delete this question but, once in a while someone has the same issue, so I will leave this here hoping perhaps it helps someone in need.

AppCompat Error onCreate()

I just imported my project which worked fine from Eclipse to Android Studio v1.2.11 and now the project is no longer working with the following error which make the app crashes at onCreate() method:
java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV11.
I have updated updated my app to the latest v7 library, i.e. 22.1.1. below is my gradle.build dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.android.support:support-v4:19.1.0') {
force = true
}
compile('com.google.android.gms:play-services-base:7.3.0') {
force = true
}
compile 'com.google.android.gms:play-services-plus:7.3.0'
compile 'joda-time:joda-time:2.7'
compile 'com.google.http-client:google-http-client-gson:1.20.0'
compile 'com.parse.bolts:bolts-android:1.1.2'
compile('com.facebook.android:facebook-android-sdk:3.22.0#aar') {
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'bolts'
}
compile 'com.google.guava:guava:18.0'
compile project(':PullToRefreshListView')
compile project(':CircularImageView')
compile project(':CountryPicker')
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v13:22.1.1'
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
NB: I am using Theme.AppCompat.Light in my styles which I believe supports ActionBar. What I want to achieve is the Nav. drawer but the app doesn't go past the onCreate(). Any help with this exception will be highly appreciated
For anyone having similar issue, I was able to solve this and thought I should share with others. The error was due to my configuration as I was excluding the android.support in my project. Once I commented it, it just vanished.
Make sure your class dependency is in your application specific build.gradle file, not your global build.gradle file.

Crouton depends on libraries but is not a library itself

I'm using Android Studio 0.6.1, with Crouton library and today after gradle sync I got next error:
Error:A problem occurred configuring root project 'project_name'.
Module version de.keyboardsurfer.android.widget:crouton:1.8.4 depends on libraries but is not a library itself
That's going on?
This issue due to com.android.support-v4 recent update.
So I changed
compile 'com.android.support:support-v4:20.+'
to
compile 'com.android.support:support-v4:19.1.+'
and crouton works fine
Different workaround is to use #aar:
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
My solution according to #Revedko answer, using #aar and change all supports to version lower than 21 -> 20.+
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.+'
compile "com.bugsense.trace:bugsense:3.5"
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.0.77'
}

Categories

Resources