I'm having a lot of trouble moving source code from github to Android Studio and I think a big part of the problem is with the gradle build tool files. I have never worked with android studio before and don't have a whole lot of coding experience in general. The gradle sync error I'm getting right now is
Error:(57,0) Plugin with id 'com.android.library' not found.
I feel like part of the problem might be the way in which i added the actionbarsherlock library. I had to add a lot of folders and so my pathways might be causing problems. Is that a possibility? I can include screenshots if that may be more helpful.
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':library')
}
android {
compileSdkVersion 19
buildToolsVersion "25.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
debug{
debuggable = true
}
}
}
Related
Hello i build an android app using gradle in eclipse. I allways build the project in command line using gradle. Now i try to build and run it in eclipse on android device emulator. In eclipse i don't know how can i build the project with gradle an run it on android emulator device. Please i need help.
You can find my buil.gradle file bellow
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':appcompat_v7')
compile "org.igniterealtime.smack:smack-android:4.1.0-rc1"
compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1"
// optional features
compile "org.igniterealtime.smack:smack-android-extensions:4.1.0-rc1"
}
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
android {
lintOptions{
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Did you try adding the gradle eclipse plug-in
apply plugin: "eclipse"
And then generate the eclipse project from build.gradle by calling
gradle eclipse
You also should install the "Gradle IDE Pack" from the eclipse marketplace (Help -> Eclipse Marketplace...).
I migrated my project to Android Studio. I have no trouble building the app and running from Android Studio. I have no trouble running the debug APK generated by Android "Generate Signed APK" option. When I want to build a release APK, I run
gradle assembleRelease
Gradle does it's stuff and finishes with BUILD SUCCESSFUL.
When I install this release APK on my device, it crashes immediately due do a missing dependency for (ironically) Crashlytics. I have added the Crashlytics jar as per their instructions.
I am very confused as to why gradle seems to work in general, but just not for the release. Any suggestions are really appreciated!
Here is the main build.gradle
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:19.0.+'
compile project(':stripe')
repositories {
mavenCentral()
}
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
signingConfigs {
release {
storeFile file(****)
storePassword "****"
keyAlias "****"
keyPassword "****"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
lib.srcDirs
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Here is the build.gradle for stripe:
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java','src/test/java']
resources.srcDirs = ['src/main/java','src/test/java']
aidl.srcDirs = ['src/main/java','src/test/java']
renderscript.srcDirs = ['src/main/java','src/test/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
}
}
Hemal from Crashlytics here, I can totally help with this! Go ahead and quickly run through the setup instructions here. That'll take care of the errors you're seeing :)
I have a jar in lib folder and added this lib as File dependency.
Generating build with ./gradlew build is successful.
But ./gradlew connectedInstrumentTest is showing Multiple dex error for that jar added in lib folder.
suggest me what is going wrong here.
build.gradle
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Module Dependency:
lib folder in project:
I am getting this error
Project is using an old version of the Android Gradle plug-in. The minimum supported version is 0.6.3.
Please update the version of the dependency 'com.android.tools.build:gradle' in your build.gradle files.
So i did research and realized I had to go to my project build.gradle file and change this part of my dependencies
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
but my build.gradle file doesnt have that. This is my build.gradle file
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':Desktop:Coding:SlidingMenu-master:library')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
What am I missing?
EDIT:
updated code
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.4'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':Desktop:Coding:SlidingMenu-master:library')
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
new error
No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (org.gradle.api.internal.file.collections.DefaultConfigurableFileTree) values: [directory 'libs']
Possible solutions: module(java.lang.Object)
<a href="error in file: C:\Users\cmtc\Documents\Android\StayHealthy\build.gradle at line: 10">Build file 'C:\Users\cmtc\Documents\Android\StayHealthy\build.gradle' line: 10
You are missing a buildscript { ... } block containing the dependencies { classpath ... } block you showed above (and also a repositories { ... } block). Such a block must be available at least in the root project's build script, or apply plugin: "android" won't work.
I have an Android project which was created in Eclipse, exported as Gradle build file, then opened in Android Studio. (Yes, it would be far easier to create a clean project in AS but I need to support the current project structure.)
Otherwise things are now mostly working, but there's still some stuff to be ironed out.
In every Activity class, AS shows this error: Class requires API level 1 (current min is -1): Activity
Alt+Enter offers to fix that with a #TargetApi annotation... but why should I have to do that, when in AndroidManifest.xml, we have:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
AndroidManifest.xml is located at project root (Eclipse default?). Looks like Android Studio is not correctly reading the settings in it. The project still compiles fine though.
Any idea how to get rid of the error?
The Eclipse-generated build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Try to add to the build.gradle following lines right after buildToolsVersion:
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
}