I did everything as it is explained on all forums but i still get the same error.I did everything as described here http://tools.android.com/tech-docs/new-build-system/migrating-from-eclipse-projects
Here is my code in build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
'com.android.tools.build:gradle:1.0.0-rc4'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "21.1.1"
buildTypes { release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt' } }
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 doing wrong?
Try change 'com.android.tools.build:gradle:1.0.0-rc4' to 'com.android.tools.build:gradle:1.0.0' at dependencies.
change your current dependencies like
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
Related
For some unknown reason Gradle is refusing to download every dependancy that I put in my gradle.build file. I'm trying to get the 'me.dm7.barcodescanner:zbar:1.7' dependancy but every time I try to sync my gradle it just gives me the following error:
Error:(6, 13) Failed to resolve: me.dm7.barcodescanner:zbar:1.7
It's not just the zbar library either, it's every library this isn't a com.android library. I'm not in offline mode so that can't be it either. Is there something wrong in my .build file?
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':MetaioSDK')
compile 'com.android.support:support-v4:22.0.0'
compile 'me.dm7.barcodescanner:zbar:1.7'
}
android {
compileSdkVersion 19
buildToolsVersion "21.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 = ['../../templatesContent_crossplatform']
}
// 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')
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
Alright, managed to fix it. Added this inside the dependencies block:
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'me.dm7.barcodescanner:zbar:1.7'
}
android {
compileSdkVersion 22
buildToolsVersion "22.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']
}
instrumentTest.setRoot('tests')
}
}
Put repository block independently from from other blocks
Recently I migrated my project to Android Studio. The project references a library project without copying it (See this answer).
I noticed that the apk generated from Android Studio is larger than the one generated from Eclipse (almost twice larger). When I unrar the two apk files I see that in the apk from Android Studio there is one more folder "main" and it contains "res" folder and AndroidManifest.xml.
The problem is that there is "res" folder (/res) in apk's main directory which contains the same resources (/main/res).
I think that the next gradle file causes the problem but without it the project can not be built.
build.gradle for my library module - my_android_project_lib module
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
// I think this duplicates the resources
sourceSets {
main {
manifest.srcFile 'my_android_project_lib/src/main/AndroidManifest.xml'
java.srcDirs = ['my_android_project_lib/src']
resources.srcDirs = ['my_android_project_lib/src']
aidl.srcDirs = ['my_android_project_lib/src']
renderscript.srcDirs = ['my_android_project_lib/src']
res.srcDirs = ['my_android_project_lib/src/main/res', 'slidingMenuLib/src/main/res']
assets.srcDirs = ['my_android_project_lib/src/main/assets']
}
}
}
dependencies {
compile project(':slidingMenuLib')
compile fileTree(dir: 'my_android_project_lib/libs', include: ['*.jar'])
compile fileTree(dir: 'slidingMenuLib/libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:1.7.1'
}
settings.gradle
include ':my_android_app'
include ':my_android_project_lib'
include ':slidingMenuLib'
project(':my_android_project_lib').projectDir = new File(settingsDir, '../my_android_project_lib')
build.gradle for my_android_app module
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my.android.app"
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(path: ':my_android_project_lib')
}
build.gradle for my_android_app project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Do you know how to fix the problem? I'm missing something important.
I found the problem. When I removed the following line from my build.gradle of my_android_project_lib module, application's size changed back to normal.
resources.srcDirs = ['anyoption_android_v2_lib/src']
The final build.gradle for my_android_project_lib module is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
// The problem is here.
sourceSets {
main {
manifest.srcFile 'my_android_project_lib/src/main/AndroidManifest.xml'
java.srcDirs = ['my_android_project_lib/src']
res.srcDirs = ['my_android_project_lib/src/main/res']
// Removed
// resources.srcDirs = ['my_android_project_lib/src'] - MAIN PROBLEM
// aidl.srcDirs = ['my_android_project_lib/src']
// renderscript.srcDirs = ['my_android_project_lib/src']
// res.srcDirs = ['my_android_project_lib/src/main/res', 'slidingMenuLib/src/main/res']
// assets.srcDirs = ['my_android_project_lib/src/main/assets']
}
}
}
dependencies {
compile project(':slidingMenuLib')
compile fileTree(dir: 'my_android_project_lib/libs', include: ['*.jar'])
compile fileTree(dir: 'slidingMenuLib/libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:1.7.1'
}
on commenting
resources.srcDirs = ['src']
in build.gradle file, worked for me.
The SourceSets in build.gradle file looks like this,
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')
}
i have previous code in eclipse-NDK and it is in running successfully in eclipse i need to import this project into android studio and run ,but it is now showing a run-time error (unfortunately force close) error why is it happened if it is clean code need a help urgently.my build file is :buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
ndk{
moduleName "filters"
abiFilter "armeabi-v7a"
stl "gnustl_static"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
// 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')
}
}
i am getting diff gradle configuration when i migrate eclipse project has without library and with library. i am getting error when importing project with libary.does any know the exact build.graddle, settings.gradle?
1)without library project build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.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')
}
2)with library build.gradle
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':sdk:extras:google:google_play_services:libproject:google- play-services_lib')
}
android {
compileSdkVersion 18
buildToolsVersion "18.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')
}
}
}
I have this gradle build file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
classpath 'com.eriwen:gradle-css-plugin:1.2.1'
classpath 'com.eriwen:gradle-js-plugin:1.5.1'
}
}
apply plugin: 'android'
apply plugin: 'js'
apply plugin: 'css'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/cordova-2.7.0.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
}
task MinifyJSForRelease {
tasks.add(name:"copyTask2", type:Copy){
from 'assets/'
into 'build/minifiedassets/assets'
}
it.dependsOn copyTask2
def tester = fileTree(dir:"build/minifiedassets/assets", include:"**/*.js");
println tester
tester.eachWithIndex {File file, idx ->
tasks.add(name: "makeMinifyJS${idx}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = file
dest = "${file.path}"
closure {
compilerOptions.languageIn = "ECMASCRIPT5"
}
}
}
it.dependsOn tasks.matching { Task task -> task.name.startsWith("makeMinifyJS")}
}
build.dependsOn MinifyJSForRelease
android {
compileSdkVersion 17
buildToolsVersion "17"
signingConfigs {
release {
storeFile file('keystores/mobilecoe_android.keystore')
storePassword "mobilecoe"
keyAlias "MobileCoE"
keyPassword "mobilecoe"
}
}
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
release {
signingConfig signingConfigs.release
zipAlign true
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['build/minifiedassets/assets']
}
instrumentTest.setRoot('tests')
}
}
}
}
I Want to run the task MinifyJSForRelease like the first thing would be to copy the assets folder to where I want and then when that is finished I want to minify the JS files.
Now when I run the task it copies the folder but not reaching the end the next function says it has nothing to minify but if I run the task the second time(when the folder is already copied) it fiends it and does everything.
What am I do in wrong?
I need to:
copy folder
Get the folder and minify its js files
Could some one help me out?
I'm a total virgen to Gradle, So I can only provide you with educated guess:
unify the way you declare the dependencies
taskB.dependsOn tasksA
force the order of the task (in add of the dependency)
taskB.mustRunAfter(taskA)
add logs, to see if the task is executed VS the tasks does not do what you expect.
Adding dependencies to a task / Ordering tasks
http://www.gradle.org/docs/current/userguide/more_about_tasks.html
please, provide us with the solution once you got it !