I am trying to load native libraries in android studio. My Project build and runs but throws error when trying to load the .so file.
My Project structure is:
And my Gradle File is:
import com.android.build.gradle.tasks.PackageApplication
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:22.1.1'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
/*
signingConfigs {
release {
storeFile file(System.console().readLine("\n\$ Enter keystore path: "))
storePassword System.console().readLine("\n\$ Enter keystore password: ")
keyAlias System.console().readLine("\n\$ Enter key alias: ")
keyPassword System.console().readLine("\n\$ Enter key password: ")
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
*/
getNdkDirectory()
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
}
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')
}
buildTypes {
debug {
debuggable true
jniDebuggable true
}
}
}
/*
* JNI Hack for gradle - works alright, copies native libs over into build folder no problem
* https://gist.github.com/khernyo/4226923
*/
task copyNativeLibs(type: Copy) {
from(new File('libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'native-libs'))
}
I am trying to load the files like:
static {
System.loadLibrary("NativeAudio");
}
I Receive following error:
java.lang.UnsatisfiedLinkError: Couldn't load Plumble from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/mnt/asec/com.morlunk.mumbleclient-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.morlunk.mumbleclient-1/lib, /vendor/lib, /system/lib, /system/lib/arm]]]: findLibrary returned null
I tried many refrences but unable to solve the issue. Using Android Studio and Gradle Version: 1.2.3
Unlike Eclipse with ADT, gradle with Android plugin looks for native libraries in src/main/jniLibs folder by default.
You can change that folder location in the following source set:
android {
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}
}
Related
I am trying to incluide FaceBook Sdk 4.2 in my app. When I import this module , it´s all rigth, but when my app run the following occurs:
Error:A problem occurred configuring project ':Glam Main'.
> Could not resolve all dependencies for configuration ':Glam Main:_debugCompile'.
> Could not find com.parse.bolts:bolts-android:1.2.0.
Searched in the following locations:
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.pom
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.jar
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.pom
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.jar
Required by:
Glam Main:Glam Main:unspecified > com.facebook.android:facebook:4.2.0
gradle.Module.Glam Main:Glam Main:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':appcompat_v7_21')
compile project(':appcompat_v7_21-cardview')
compile project(':appcompat_v7_21-recyclerview')
compile project(':httpmime-4.2.6')
compile project(':facebook')
}
android {
compileSdkVersion 21
buildToolsVersion "20.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')
}
}
In my module Facebook , I have added com.parse.bolts:bolts-android:1.2.0. this module Facebook has been imported correctly because i can work with their classes.
Here my gradle.Module.Facebook
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
compile 'com.android.support:support-v4:[22,23)'
compile 'com.parse.bolts:bolts-android:1.2.0'
}
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
apply plugin: 'maven'
apply plugin: 'signing'
def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
task setVersion {
// The version will be derived from source
project.version = null
def sdkVersionFile = file('src/com/facebook/FacebookSdkVersion.java')
sdkVersionFile.eachLine{
def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
if (matcher.matches()) {
project.version = matcher[0][1]
return
}
}
if (project.version.is('unspecified')) {
throw new GradleScriptException('Version could not be found.', null)
}
}
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Facebook-Android-SDK'
artifactId = 'facebook-android-sdk'
packaging 'aar'
description 'Facebook Android SDK'
url 'https://github.com/facebook/facebook-android-sdk'
scm {
connection 'scm:git#github.com:facebook/facebook-android-sdk.git'
developerConnection 'scm:git#github.com:facebook/facebook-android-sdk.git'
url 'https://github.com/facebook/facebook-android-sdk'
}
licenses {
license {
name 'Facebook Platform License'
url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
}
uploadArchives.dependsOn(setVersion)
signing {
required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// JDK 1.8 is more strict then 1.7. Have JDK 1.8 behave like 1.7 for javadoc generation
if (org.gradle.internal.jvm.Jvm.current().getJavaVersion() == JavaVersion.VERSION_1_8) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath}
I have read the follow post Android Studio 0.8.1 - how to use Facebook SDK? but I getnt resolve my problem. Thanks.
Update 1
I have modified gradle.Module.Glam Main:Glam Main. I added this sentences:
allprojects {
repositories {
jcenter()
}
}
Now i have this error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
Error:Execution failed for task ':Glam Main:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2
You can add the latest Facebook SDK via Gradle dependency:
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
Take a look to my build.gradle file:
https://github.com/lalongooo/permutas-sep/blob/master/app/build.gradle
I am trying to install Android-GPU-Image in my project. https://github.com/CyberAgent/android-gpuimage
When I download the source, it's broken down as such:
The github project does not include install instructions (other than a dependency line that didn't work for me) so I am trying to figure out how to install a package like this.
My question is: What is the general name of this 'android-gpuimage' folder in the context of adding it to a project? Is this a Module, Sub-Project, Library-Project or what?
Update
Here is my gradle file
import java.util.regex.Pattern
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
project.ext {
multiarch = false
compileSdkVersion = Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
minSdkVersion = Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion = Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
buildToolsVersion = project.ANDROID_BUILD_TOOLS_VERSION
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
compile project(':CordovaLib')
compile project(':app-FacebookLib')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/twitter4j-core-4.0.3.jar')
compile files('libs/twitter4j-core-4.0.4-SNAPSHOT.jar')
compile files('libs/Filters.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
}
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
def getVersionCodeFromManifest() {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return Integer.parseInt(matcher.group(1))
}
Answer:
Needed to add
repositories {
mavenCentral()
}
To my gradle, the one I already had was in the build script, I needed it outside that scope too.
https://stackoverflow.com/a/16675271/3324388
What you have checked out of github is the entire project , which containes the library project and a sample project showing how to use the library.
To use the library , you would have to include the dependency in gradle as mentioned
dependencies {
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
}
The gradle file lets you know what kind of project it is
for example ,a library project would have
apply plugin: 'com.android.library'
and the main application project would have
apply plugin: 'com.android.application'
I am new in phone gap.integrated facebook plugin in my project .after running error showing
`Error:A problem occurred configuring root project 'android'.'
Could not resolve all dependencies for configuration ':_debugCompile'.
Could not find com.parse.bolts:bolts-android:1.1.2.
Searched in the following locations:
file:/C:/Users//AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.1.2/bolts-android-1.1.2.pom
file:/C:/Users//AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.1.2/bolts-android-1.1.2.jar
file:/C:/Users//AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.1.2/bolts-android-1.1.2.pom
file:/C:/Users//AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.1.2/bolts-android-1.1.2.jar
Required by:
:android:unspecified > com.facebook.android:FacebookLib:3.21.1
pls help me.
import java.util.regex.Pattern
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
compile 'com.parse.bolts:bolts-android:1.1.2'
}
}
ext.multiarch=false
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
for (subproject in getProjectList()) {
compile project(subproject)
}
compile files('com.phonegap.plugins.facebookconnect/FacebookLib/libs/bolts-android-1.1.2.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
}
compileSdkVersion 19
buildToolsVersion "19.1.0"
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
def getVersionCodeFromManifest() {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return Integer.parseInt(matcher.group(1))
}
def getProjectList() {
def manifestFile = file("project.properties")
def pattern = Pattern.compile("android.library.reference.(\\d+)\\s*=\\s*(.*)")
def matcher = pattern.matcher(manifestFile.getText())
def projects = []
while (matcher.find()) {
projects.add(":" + matcher.group(2).replace("/",":"))
}
return projects
}
Try it may be helpful.
Failed to resolve : compile 'com.parse.bolts:bolts-android:1.+'
Go to menu : File -> Settings - > Build, Execution, Deployment - > Build Tools -> Gradle
In - Project-level-setting
Checked or select- User default gradle wrapper(recommended)
and
In - Global Gradle Setting
Disable offline Work
You're missing the repositories declaration in your script. What you do have is the repositories in buildscript closure, that configures the build itself (e.g. to find the Android plugin needed for the build to run), but you don't have a repositories declaration that will bring the dependencies your classes need.
Please add
repositories {
jcenter()
}
That should do the trick.
Not able to solve this error, I have updated Android studio. gone throungh other this solutions but not worked for me, please help..
Build script error, unsupported Gradle DSL method found: 'release()'!
Possible causes could be:
- you are using Gradle version where the method is absent
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
Gradle settings
Gradle version - 0.9
Main gradle.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
}
Project Gradle file
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion '18.0.1'
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
signingConfigs {
release {
storeFile file('dsc.jks')
storePassword 'dscneo'
keyAlias 'dsc'
keyPassword 'dscneo'
}
}
buildTypes {
debug {
versionNameSuffix '-DEBUG'
}
beta {
versionNameSuffix '-BETA'
}
release {
signingConfig signingConfigs.release
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.android.support:support-v4:+'
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/gson-2.1.jar')
compile project(':facebook')
compile project(':TabIndicatorLibrary')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile project(':VerticalViewPager')
compile files('libs/universal-image-loader-1.9.1.jar')
compile files('libs/universal-image-loader-1.9.1-sources.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
compile files('libs/HockeySDK-3.0.1.jar')
}
Facebook SDK gradle file
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 17
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')
}
}
Other library project gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 16
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')
}
}
one more library project gradle file.
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
In your last file (library) you have the release block inside the android block.
The DSL for the library projects is now the same as for the application projects
In particolar you have to put the release block inside the buildTypes.
android {
buildTypes {
release {
}
}
Also I suggest you use buildToolsVersion '19.0.x' for all your gradle files.
You can put it in your build.gradle in root folder.
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.3"
}
Then in each build.gradle file you can use:
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
I have android project and android test project inside it, located under folder tests. Structure of these project is eclipse like
+-src
| - res
| - libs
| - tests
|.....
I use gradle. All i want is to build app, run unit tests and get reports of them. But i don't understand how to do it right. I'm created build.gradle file in root folder
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
unitTest {
java.srcDir file('tests/src')
resources.srcDir file('tests/res')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
}
task unitTest(type:Test){
description = "Run unit tests..."
testClassesDir = android.sourceSets.unitTest.output.classesDir
classpath = android.sourceSets.unitTest.runtimeClasspath
}
build.dependsOn unitTest
}
But when i run gradle build i got error
Could not find property 'output' on source set unit test.
Also, as i understand, to get reports i need to apply plugin "android-reporting", but when i do this i got error
Cannot add extension with name 'android', as there is an extension already registered with that name.
Should i do it like this, or i must create new gradle.build file in my test application project?
UPDATE
I fixed error with output, and made gradle build successful, but I don't understand what's goind on. I purposely failed my test, but gradle build is still successful.
What I've done:
1. I moved task unitTest from android section to root, after that, my test project began to compile, but there is an error 'packackage android.test not found'
2. To fix that error I added to classpath path to android sources, so after that gradle build was successful, but realy I don't understand why it's always successful even when test fails
And still I don't understand how to get reports from test
This is my new build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile file('AndroidManifest.xml')
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
sourceSets {
unitTest {
java.srcDirs = ['tests/src']
resources.srcDirs = ['tests/src']
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.11'
compile fileTree(dir: 'libs', include: '*.jar')
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = sourceSets.unitTest.output.classesDir
classpath = files("$System.env.ANDROID_HOME/sources/android-18")
//actualy I didn't get any report
getReports().getJunitXml().setOutputPerTestCase(true)
}
build.dependsOn unitTest
I found solution. I was dissapointed by few topics, and thought that i need to create separate task for unit tests. In fact it was prety easy.
I didn't change my project structure, just build.gradle file. To build application i run
gradle clean connectedCheck build
connectedCheck runs unit tests from my test project and if some test fails - gradle build will fails too
Here final version of it
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile file('AndroidManifest.xml')
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest {
java.srcDirs = ['tests/src']
manifest.srcFile file('tests/AndroidManifest.xml')
resources.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
assets.srcDirs = ['tests/assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
//Signing apk
if(project.hasProperty("signingPropertiesPath")) {
File propsFile = new File(System.getenv('HOME') + "/" + project.property("signingPropertiesPath"))
if(propsFile.exists()) {
Properties props = new Properties()
props.load(new FileInputStream(propsFile))
//loading keystore properties
signingConfigs {
release {
storeFile file(propsFile.getParent() + "/" + props['keystore'])
storePassword props['keystore.password']
keyAlias props['keyAlias']
keyPassword props['keyPassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
}
}