assets dir not found - android

I am trying to add asset files to my android test project but somewhy assets from test dir are not available from inside test classes. What I am doing wrong?
The purpose is to have additional asset files for test cases.
Compilation is success from IDEA and command line, but test results are the same.
When I am trying to call getContext().getAssets().open("test.json") I have FileNotFoundException.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
debugCompile 'com.android.support:support-v13:13.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
testBuildType "debug"
sourceSets {
androidTest {
assets.srcDirs = ['src/androidTest/assets']
}
androidTest.setRoot('src/androidTest')
}
defaultConfig {
versionCode 1
versionName "1.0"
minSdkVersion 14
targetSdkVersion 19
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
debug {
applicationIdSuffix ""
}
}
}

Created an issure in the android tools project. Looks like a bug.

Related

Android project there is no output dir after gradle build success?

I am learning Gradle for Android recently. For learning impressively, i create all android application files manually.
my project dirs as below
package name : com.wonbin.gradledemo
project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
app module build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.wonbin.gradledemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "adroid.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
lintOptions {
htmlReport true
htmlOutput file("lint-results.html")
}
}
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:23.4.0'
testCompile 'junit:junit:4.12'
}
./gradlew build is successful and there are 'intermediates' and 'generated'
dirs , but no outputs dir, i don't know what to do!
Thanks a lot!
You need not only to build, but to assemble it as well.
To do this you can run a gradle task
assembleDebug
Or use Build -> Build APK main menu item

Android Gradle Unable to Find Apache Library

When I try to sync gradle, it shows this error.
Warning:Unable to find optional library: org.apache.http.legacy
My build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.myapp.mynamespace"
minSdkVersion 15
targetSdkVersion 23
versionCode 17
versionName "1.7"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions.encoding = 'UTF-8'
}
My root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
I tried to use gradle 1.3.1 and buildToolsVersion 23.0.2 but it didn't work. There aren't many questions like this and they didn't resolved out. So I needed to ask this question to come to a fine end.
I had this problem before and the way I solved it was by copying the JAR into the libs/ folder of your project, Gradle will not resolve this jar automatically.
You should have a copy in your local machine already under SDK/platforms/android-23/optional

Android Studio - Error Building - Android tasks have already been created

Getting the following error when building the project:
Error:(2, 0) Android tasks have already been created.
This happens when calling android.applicationVariants,
android.libraryVariants or android.testVariants.
Once these methods are called, it is not possible to
continue configuring the model.
Root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
versionCode 5
versionName '5'
targetSdkVersion 19
minSdkVersion 10
applicationId 'tsp.movil'
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:support-v4:22.1.1'
}
App build.gradle:
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "tsp.movil"
minSdkVersion 10
targetSdkVersion 19
versionCode 5
versionName '5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/zbar.jar')
}
Your Top Level build.gradle file should only have the configuration common for all modules of your project.
make the following changes :
Root build.gradle file should have only this piece of code
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects{
repositories {
jcenter()
}
}
I've faced a similar issue, with the same error message. The issue in my case was that I've had created a module inside a package and then deleted it manually in (MacOS) Finder.
The problem was that I forgot to also remove the include ::myModule line from the settings.gradle file.
look on this:
How to define common android properties for all modules using gradle
the 3rd comment says Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

Building flavors and defaultConfig using play button in Android Studio

I have created the following gradle.build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName '1.0'
applicationId 'com.kibo.mobi.app'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flavor1{
applicationId 'com.kibo.mobi.flavor1'
minSdkVersion 14
targetSdkVersion 20
}
flavor2{
applicationId 'com.kibo.mobi.flavor2'
minSdkVersion 14
targetSdkVersion 20
}
}
sourceSets {
flavor1{
manifest.srcFile 'flavor1/AndroidManifest.xml'
assets.srcDirs = ['src/flavor1/assets']
}
flavor2{
manifest.srcFile 'flavor2/AndroidManifest.xml'
assets.srcDirs = ['src/flavor2/assets']
}
}
}
dependencies {
compile project(':AppSDK')
}
Pressing the Play/Run button in Android Studio results in building, compiling and installing the "flavor1" version on the connected device.
How can I manually configure what version will be installed? When the default version (not a flavor - but the "main" folder) is also a version I need to install sometimes. So basically there are 3 version here that I need to have the ability to install each one of them as requested.
The "Build Variants" tool window (View menu > Tool windows > Build variants) lets you select which flavor + build type combination will be built and run by default.

Android studio - Build script error, unsupported Gradle DSL method found: 'android()'!

I'm getting the following error in Android Studio 0.4.2 when I'm trying to Sync project with gradle.
Gradle 'GooglePlayServicesTest' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'android()'!
My projects gradle file is as follows :-
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
android{
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
sourceSets{
main{
manifest.srcFile 'GooglePlayServicesTest/src/main/AndroidManifest.xml'
}
}
}
gradle file of module:-
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
also I have removed the miniSDKVersion and targetSDKVersion from AndroidManifest.xml
can someone help me to solve this error.
android method in project gradle file is not needed.Try to remove it.
Add top of your project build.gradle file:
apply plugin: 'com.android.application'

Categories

Resources