Android Studio V1.0.2,Error:(2, 0) Gradle DSL method not found: 'compile()'? - macos

Android Studio 1.0.2 with gradle 1.0.0 on Mac
when I start a new project,gradle project sync failed with errors:
Error:(2, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'My Application' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
build.gradle under project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle under app
dependencies {
compile 'com.android.support:appcompat-v7:21.+'
}
apply plugin: 'com.android.application' android {
compileSdkVersion 21 buildToolsVersion "21.1.1" defaultConfig {
applicationId "com.macernow.djstava.myapplication" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0"
} buildTypes {
release {
minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile 'com.android.support:appcompat-v7:21.+' compile fileTree(dir: 'libs', include: ['*.jar'])
}
And I also try online/offline gradle settings,the error remains.Please help me,thanks.

Uninstall Android Studio cleanly by
rm -Rf /Applications/Android\ Studio.app
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/com.google.android.studio.plist
rm -Rf ~/Library/Application Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*
And then reinstall it,everything is OK.

Related

Gradle not finding org.apache.commons:commons-imaging

Gradle cannot resolve org.apache.commons:commons-imaging, yet it is available in all 3 of the provided repositories:
http://jump-pilot.sourceforge.net/repository
https://repo.adobe.com/nexus/content/repositories/public/
https://repository.apache.org/content/repositories/snapshots/
This part of the log is interesting, Gradle looks only in jcenter and the local filesystem:
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
Console log (requesting org.apache.commons:commons-imaging:1.0-SNAPSHOT):
$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find org.apache.commons:commons-imaging:1.0-SNAPSHOT.
Searched in the following locations:
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
https://jcenter.bintray.com/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
file:/Users/user/Library/Android/sdk/extras/android/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.pom
file:/Users/user/Library/Android/sdk/extras/google/m2repository/org/apache/commons/commons-imaging/1.0-SNAPSHOT/commons-imaging-1.0-SNAPSHOT.jar
Required by:
ReactNativeProject:app:unspecified > ReactNativeProject:react-native-image-store-ext:unspecified
Console log (requesting org.apache.commons:commons-imaging:+):
$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find any matches for org.apache.commons:commons-imaging:+ as no versions of org.apache.commons:commons-imaging are available.
Required by:
ReactNativeProject:app:unspecified > ReactNativeProject:react-native-image-store-ext:unspecified
build.gradle:
buildscript {
repositories { jcenter() }
dependencies { classpath 'com.android.tools.build:gradle:2.1.0' }
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions { abortOnError false }
}
repositories {
mavenCentral()
maven { url "http://jump-pilot.sourceforge.net/repository" }
maven { url "https://repo.adobe.com/nexus/content/repositories/public/" }
maven { url "https://repository.apache.org/content/repositories/snapshots/" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile "com.facebook.react:react-native:+"
compile 'org.apache.commons:commons-imaging:+'
}
There are 2 build.gradle file in android project: the one inside main project folder and the one inside app folder. The repository should be defined under allprojects block inside project folder. Here, example of my build.gradle which successful build apache commons imaging.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "http://jump-pilot.sourceforge.net/repository" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Apparently, there is no oficial version for apache commons imaging yet.
The latest unoficial version I have found, is on this repo
maven { url "http://wcm.io/maven/repositories/apache-intermediate-release/" }
Add this line on the build.gradle as opris said.
Then, in your gradle app/module file, add this
dependencies {
...
implementation 'org.apache.commons:commons-imaging:1.0-R1725432'
...
}
I haven't tested it yet, so I will have to choose between this one and the oficial version of sanselan,
compile 'org.apache.sanselan:sanselan:0.97-incubator'
which has no more support

how to add repositories and dependencies in Gradle for android . Actually am trying to integrating SDk in my existing app

Can Anyone explain me what is Version Tag for git in this, I am getting error while importing this.
apply plugin: 'com.android.application'
buildscript {
repositories {
maven { url 'https:example.com' }
jcenter()
mavenCentral()
mavenLocal()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jatinder.bdugame"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG'
}
Error:
Error:(45, 13) Failed to resolve: org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG
Show in File<br>Show in Project Structure dialog
What does you question have to do with Git or Maven?
It does not even have anything to do with Android, besides coming from an Android project.
You declared the compile time dependency org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG which means group org.bitbucket.5elements, artifact SmartTones-SDK, version VERSION_TAG. This combination is not found in any of your declared repositories, so it fails to be resolved, just as the error tells you.

My Android Studio Project's APK is not zip aligned (Upload Failure)

I keep on failing to upload the signed APK file generated from Android Studio, even though I have tried many different solutions to solve it.
This is what I get when uploading:
I have also seen some solutions to write zipalign commands, but I always get the "command not found" message when entering the command in my mac's terminal.
And this is my configuration in the build.gradle (Module: app) file inside the project:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.name.product"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
}
}
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile(name:'material-search', ext:'aar')
}
I found this solution and it solved my problem:
https://stackoverflow.com/a/37842438/4846301
It was all about changing 1 line in the build.gradle file to this:
'com.android.tools.build:gradle:2.1.2'

Adding a Maven dependency (XML) on a Android Studio project

I'm trying to use this Java library in my Android app. From the documentation, I have to put compile "json-to-pdf:json-to-pdf:0.7.5" in my build.grade dependencies. When I try to sync the project, I get an error:
Error:(39, 13) Failed to resolve: json-to-pdf:json-to-pdf:0.7.5
I asked the owner, but he does not know how to fix it. I think I have to add the following Maven dependencies in build.grade too:
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
But I dont't know how to do that.
Here is my settings so far:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileOptions.encoding = 'ISO-8859-1'
defaultConfig {
applicationId "br.com.app"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
//mavenCentral() I tried that but doesn't work
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
...
compile 'json-to-pdf:json-to-pdf:0.7.5' // Doesn't work
}
You have to define the clojars Maven repository in your build.gradle.
repositories {
jcenter()
maven {
url 'http://clojars.org/repo'
}
}
The author of this library should probably add this to the GitHub readme.
Update: I responded to the GitHub issue with the appropriate Gradle snippet that should be added to the docs.

Problen add dependency android studio

I posted my library in Artifactory
https://imagizer.imageshack.us/v2/806x253q90/631/kkK1Yn.png
this is my Gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle',
version: '3.0.1')
}
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
url 'http://myartifactory:8081/artifactory/gradle-local'
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.android.library'
apply plugin: 'android-apt'
def AAVersion = '3.2'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
}
}
dependencies {
compile fileTree(include: ['*.jar', '*.so'], dir: 'libs')
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'it.sephiroth.android.exif:library:+'
compile 'com.joanzapata.android:android-iconify:1.0.8'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.afollestad:material-dialogs:0.6.0'
compile 'com.github.lzyzsd:circleprogress:1.0.1#aar'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile(group: 'com.mylibrary.android.common', name: 'android.common', version: '1.0.0', ext: 'aar')
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.mypackage.library'
}
}
I get this error
https://imagizer.imageshack.us/v2/519x72q90/540/8ojerK.png
Gradle I found that running the route using the url wrong use "/" instead of "."
Try to find
...8081/artifactory/repo/com/mypackage/android/common/android.common/1.0.0/android.common-1.0.0.aar
but should be
...8081/artifactory/repo/com.mypackage.android.common/android.common/1.0.0/android.common-1.0.0.aar
I'm doing wrong, wrong as was published in the artefactory
Your artifact is not complaint to the standard Maven layout, in which the groupId should be separated by /, not by ..
It's not a big deal, Gradle can handle it easly, you just can't declare the repository as maven, but as ivy instead.
Actually, it will be easier to use the artifactory plugin for resolution, it also supports both Maven and Ivy layouts.
Also, please remember to set the repository in Artifactory to be with correct layout (not Maven2, probably Ivy).
And frankly, I think maybe it worth redeploying the artifact under Maven layout, it will make your life easier.

Resources