trying to run android tests in android studio 0.8.1
I can run assembleDebug and assembleTest properly. But when I try to run the android test it calles assembleDebug and assembleDebugTest and with the latter I get the problem with 'Multiple dex files define'
a few pictures:
and the build.gradle of the project
dependencies {
compile project(':libraries:someLib')
compile ('com.google.android.gms:play-services:5.+')
compile ('fr.avianey:facebook-android-api:+#aar')
compile ('com.fasterxml.jackson.core:jackson-databind:2.3.1')
compile ('com.fasterxml.jackson.core:jackson-core:2.3.1')
compile ('com.fasterxml.jackson.core:jackson-annotations:2.3.0')
compile fileTree(dir: 'libs', include: '*.jar')
//androidTestCompile 'junit:junit:4.10'
//androidTestCompile 'org.robolectric:robolectric:2.1.+'
//androidTestCompile 'com.squareup:fest-android:1.0.+'
//androidTestCompile 'org.powermock:powermock-api-mockito:1.5.1'
}
and the build.gradle of the "someLib"
dependencies {
compile ('com.android.support:appcompat-v7:19.1.+')
compile ('com.nineoldandroids:library:2.4.0')
compile (group: 'com.google.guava', name: 'guava', version: '16.0-rc1')
}
they both share the rest
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
lintOptions {
abortOnError false
}
}
So far I tried 2 solutions that seems to work but I am pretty sure there has to be something better.
Anyway 1 solution:
tasks.whenTaskAdded { theTask ->
if("assembleDebugTest".toString().equals(theTask.name.toString())) {
def yourTaskName = "cleanLibs"
project.task(yourTaskName) << {
println "${project.buildDir}/intermediates/pre-dexed/test/debug/"
delete fileTree(dir: ("${project.buildDir}/intermediates/pre-dexed/test/debug/"))
}
theTask.dependsOn(yourTaskName)
def processTask = "preDexDebugTest"
project.(yourTaskName.toString()).dependsOn(processTask)
project.(processTask.toString()).dependsOn("compileDebugTestJava")
}
}
this removes the libs before they are created again, it is slow and ungly, let the libs be created, removes them and creates them again
solution 2:
tasks.whenTaskAdded { theTask ->
if("assembleDebugTest".toString().equals(theTask.name.toString())) {
def processTask = "preDexDebugTest"
project.(processTask.toString()).enabled = false
}
}
just skip the task that create the first libs, this is way better than the first one
then for both you have to extend
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'com/flurry/org/codehaus/jackson/map/VERSION.txt'
exclude 'com/flurry/org/codehaus/jackson/impl/VERSION.txt'
exclude 'com/flurry/org/apache/avro/data/Json.avsc'
exclude 'META-INF/ASL2.0'
}
}
by whatever is twice
Related
I am running Nix on top of Devuan GNU/Linux system (x86_64), with following ~/.nixpkgs/config.nix, as documented in Nix Pills:
{
packageOverrides = pkgs: {
coreutils = pkgs.coreutils.override {
aclSupport = false;
attrSupport = false;
selinuxSupport = false;
};
coreutils2 = pkgs.coreutils.override {
aclSupport = false;
attrSupport = false;
selinuxSupport = false;
};
w3m = pkgs.w3m.override {
graphicsSupport = false;
imlib2 = null;
x11Support = false;
mouseSupport = true;
};
};
}
But when I run nix-env -iA nixpkgs.coreutils, Nix installs stock version of coreutils, with optional features enabled:
$ nix-env -iA nixpkgs.coreutils
replacing old 'coreutils-8.31'
installing 'coreutils-8.31'
$ ldd /home/iu/.nix-profile/bin/ls |grep libattr
libattr.so.1 => /nix/store/5xwmn6ai8c42j84k6gdzja0lnkdi3c60-attr-2.4.48/lib/libattr.so.1
(0x00007f0354e7f000)
But if I refer to same derivation (referential transparency) via other name:
$ nix-env -iA nixpkgs.coreutils2
Nix starts rebuild from source, which results in binaries, compiled without optional features, just as requested. What is even more mysterious, overriding build options for w3m works and do trigger rebuild.
Also, I noticed same strange behavior with gnutar. Is is somehow related to the fact that coreutils and gnutar are essential to Nix itself? How can I make coreutils in expected way?
This happens because one final overlay is applied after your overlays. (You're using packageOverrides which becomes essentially the first user overlay)
To quote the commit:
The stdenvOverrides overlay is used to bring packages forward during
bootstrapping via stdenv.overrides. These packages have already had
the overlays applied to them in the previous boostrapping stage. If
stdenvOverrides is not last in the overlays stack, all remaining
overlays will windup being applied again to these packages.
gnutar is also set by this overlay.
$ nix repl '<nixpkgs>'
nix-repl> lib.attrNames (stdenv.overrides pkgs pkgs)
[ "acl" "attr" "bash" "binutils" "binutils-unwrapped" "bzip2" "coreutils" "diffutils" "findutils" "gawk" "gcc" "glibc" "gnugrep" "gnumake" "gnupatch" "gnused" "gnutar" "gzip" "patchelf" "pcre" "xz" "zlib" ]
The "good" news is you can use a normal overlay to configure the last overlay. It's convoluted but it works:
nix-repl> (import <nixpkgs> { overlays = [ (self: super: { stdenv = super.stdenv // { overrides = self2: super2: super.stdenv.overrides self2 super2 // { coreutils = "put your coreutils here"; }; }; }) ]; }).coreutils
"put your coreutils here"
I recommend using overlays instead of packageOverrides to make sure this happens in the last "user" overlay.
So your overlay would be similar to:
_: super:
let
coreutils = pkgs.coreutils.override {
aclSupport = false;
attrSupport = false;
selinuxSupport = false;
};
in
{
# Overrides for stuff from stdenv go here. They're applied last
# so we use the same stdenv for builds but a custom coreutils etc for
# our system. This allows use to still use cache.nixos.org.
stdenv = super.stdenv // {
overrides = self2: super2: super.stdenv.overrides self2 super2 // {
inherit coreutils;
};
};
w3m = ...;
}
I'm trying to add Spek testing framework to my Android Studio project. Following the instructions Here, I ended up adding the following to my module build.gradle:
testCompile 'org.jetbrains.spek:spek-api:1.1.5'
testCompile 'junit:junit:4.12'
testCompile "org.junit.platform:junit-platform-runner:1.0.0"
testRuntimeOnly 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
Then I annotated my test with #RunWith(JUnitPlatform::class)
However, when I try to run the test, I get:
org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
Any idea what am I missing?
(For future references)
To use Kotlin and Spek + JUnit5 in Android Studio you need the following:
In project's build.gradle you need to have:
buildscript {
ext.kotlin_version = '1.2.10'
ext.JUnit5_version = '1.0.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:$JUnit5_version"
}
}
In module's build.gradle you need to have:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "de.mannodermaus.android-junit5"
android {
...
sourceSets {
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
}
project.ext {
spekVersion = "1.1.5"
}
dependencies {
...
//
// TESTS
testImplementation("org.jetbrains.spek:spek-api:$spekVersion") {
exclude group: "org.jetbrains.kotlin"
}
testImplementation("org.jetbrains.spek:spek-junit-platform-engine:$spekVersion") {
exclude group: "org.junit.platform"
exclude group: "org.jetbrains.kotlin"
}
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation junit5.unitTests()
// see https://github.com/mannodermaus/android-junit5#android-studio-workarounds
testCompileOnly junit5.unitTestsRuntime()
}
Simple Spek test
class ExampleSpekTest : Spek({
val x = 2
val y = 3
given("x = $x and y = $y") {
val sum = x + y
it("should be that x + y = 5") {
Assert.assertEquals(5, sum)
}
it("should be that x - y = -1") {
val subtract = x - y
Assert.assertEquals(-1, subtract)
}
}
})
See
- official documentation http://spekframework.org/
- official plugin for running specs from the IDE https://github.com/raniejade/spek-idea-plugin
- Tests using Spek Framework - BDD Style vs JUnit Style https://www.youtube.com/watch?v=asDZ_7ZUiX4
- Simple Android configuration of Spek and JUnit5 https://gist.github.com/Mugurell/088daf42a4d60240ba6993681e0537a5
Apparently it doesn't work well... I ended up using kotlintest which is much easier to integrate
I am searching from other questions related on BuildConfig. I can't find any appropriate answers for my problem.
I want to generate apks with different version names and code, based on their variants.
For example:
Flavor1Debug.apk
versionName = 1000
versionCode = 1000
Flavor1Release.apk
versionName = 1001
versionCode = 1001
Flavor2Debug.apk
versionName = 4000
versionCode = 4000
Flavor2Release.apk
versionName = 4001
versionCode = 4001
I created a file where my flavors version stored. "version.properties"
flavor1VersionCode=1000
flavor1VersionName=1000
flavor2VersionCode=4000
flavor2VersionName=4000
Project Structure
/Projectroot
---/src
---/assets
---/res
---/jni
---/libs
---/flavor
----/flavor1
----/flavor2
Here is my gradle script sample
build.gradle
android {
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
flavor1VersionCode = versionProps['flavor1VersionCode'].toInteger()
flavor1VersionName = versionProps['flavor1VersionName'].toString()
flavor2VersionCode = versionProps['flavor2VersionCode'].toInteger()
flavor2VersionName = versionProps['flavor2VersionName'].toString()
productFlavors {
productFlavor1 {
versionCode = flavor1VersionCode
versionName = flavor1VersionCode
}
productFlavor2 {
versionCode = flavor2VersionCode
versionName = flavor2VersionCode
}
}
buildTypes {
debug {
}
release {
}
}
}
Its been seven months, I have an answer to my question.
After two weeks of research and trial and error. I finally figured out how Gradle process files upon building the application.
Here's what I did.
In application variants closure you have to modify the manifest output file, get the output variants and iterate to each manifest files.
def outputs = variant.getOutputs()
and use this implementation to update each files.
def manifestFile = "$buildDir/intermediates/manifests/full/${flavor.name}/${buildtype.name}/AndroidManifest.xml"
def updatedContent = new File(manifestFile).getText('UTF-8').replaceAll(i[0].toString(), i[1].toString())
new File(manifestFile).write(updatedContent, 'UTF-8')
In a C++ Gradle project, I use the boost 1.49 library.
How can I add this library as dependency of my project.
I try in this way, but I should define boost as dependency. There is a C++ library repository?
apply plugin: 'cpp'
libraries {
hello {
baseName 'hello'
}
}
sources {
hello{
cpp {
source.srcDirs = ['src']
lib library: 'boost', linkage: 'api'
exportedHeaders.srcDirs = ['include']
}
}
}
c/cpp programming is not but domain (in contrast to gradle ;) ) but when you navigate to $GRADLE_HOME/samples/native-binaries you can find lots of useful examples there.
One of them - cunit (oh, there's a another one: multi-project) has such configuration - it may be useful for you. Below I enclose build.gradle from cunit - in case you use gradle wrapper.
apply plugin: "c"
apply plugin: "cunit"
model {
flavors {
passing
failing
}
repositories {
libs(PrebuiltLibraries) {
cunit {
headers.srcDir "lib/cunit/2.1-2/include"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile =
file("lib/cunit/2.1-2/lib/" +
findCUnitLibForPlatform(targetPlatform))
}
}
}
}
}
libraries {
operators {}
}
binaries.withType(CUnitTestSuiteBinarySpec) {
lib library: "cunit", linkage: "static"
if (flavor == flavors.failing) {
cCompiler.define "PLUS_BROKEN"
}
}
def findCUnitLibForPlatform(Platform platform) {
if (platform.operatingSystem.windows) {
return "vs2010/cunit.lib"
// return "vs2013/cunit.lib"
// return "cygwin/cunit.lib"
// return "mingw/cunit.lib"
} else if (platform.operatingSystem.macOsX) {
return "osx/libcunit.a"
} else {
return "linux/libcunit.a"
}
}
Quick googling has shown that there's no such thing like a libraries repository for c/cpp projects. It seems that the libraries should be included in project sources.
i am working on CDT eclipse plug in development, i am trying to get the list of sources files which exist in eclipse project explorer using CDT code using following code ,which results null.
Case1:
IFile[] files2 = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI("file:/"+workingDirectory));
for (IFile file : files2) {
System.out.println("fullpath " +file.getFullPath());
}
Case2:
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(getProject().getRawLocationURI());
for (IFile file : files) {
System.out.println("fullpath " +file.getFullPath());
}
Case3:
IFile[] files3 = ResourceLookup.findFilesByName(getProject().getFullPath(),ResourcesPlugin.getWorkspace().getRoot().getProjects(),false);
for (IFile file : files3) {
System.out.println("fullpath " +file.getFullPath());
}
Case4:
IFolder srcFolder = project.getFolder("src");
Case 1 ,2,3 giving me output null, where i am expecting list of files;
in Case 4: i am getting the list of "helloworld/src" files, but i am expecting to get the files from the existing project mean main root ,ex:"helloworld"
please suggest me on this.
You can either walk through the worspace resources tree using IResourceVisitor - or you can walk through CDT model:
private void findSourceFiles(final IProject project) {
final ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
cproject.accept(new ICElementVisitor() {
#Override
public boolean visit(final ICElement element) throws CoreException {
if (element.getElementType() == ICElement.C_UNIT) {
ITranslationUnit unit = (ITranslationUnit) element;
if (unit.isSourceUnit()) {
System.out.printf("%s, %s, %s\n", element.getElementName(), element.getClass(), element
.getUnderlyingResource().getFullPath());
}
return false;
} else {
return true;
}
}
});
} catch (final CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Note there may be more source files then you actually want (e.g. you may not care system about headers) - you can filter them by checking what the underlying resource is.