For historical reason instrumentation tests are not stored in androidTests directory as required and i can't change directories structure (actually whole app is tests for the library used). I was able to build and install apk with gradle, but no tests were found:
:app-tests:connectedDebugAndroidTest
Tests on test_avd(AVD) - 4.1.2 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
com.android.builder.testing.ConnectedDevice > No tests found.[test_avd(AVD) - 4.1.2] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
:app-tests:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app-tests:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/asmirnov/Documents/dev/src/project/app-tests/build/reports/androidTests/connected/index.html
Actually the tests are in src folder, written correctly and can be built/runned using Ant:
public abstract class BaseTest extends AndroidTestCase
{
...
public class AppInfoTest extends BaseTest
{
#Test
public void testAllProperties()
{
...
...
How can i make Gradle process src folder as android (instrumentation) tests?
Here is my current build.gradle file (it uses the experimental Android Gradle plugin version 0.7.2 because we have an NDK library):
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sources {
main {
// overriding paths from default ones to actual ones
// what about 'androidTests' ?
manifest { source {
srcDir '.'
include 'AndroidManifest.xml'
} }
java { source { srcDirs = ['src'] } }
res { source { srcDirs = ['res'] } }
jni {
dependencies {
project ":library" // native library dependency
}
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
UPDATE 1 (for sschuberth):
Config:
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
androidTest {
manifest.srcFile 'AndroidManifest.xml' // error here
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
Error
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/asmirnov/Documents/dev/src/project/app-tests/build.gradle' line: 32
* What went wrong:
A problem occurred configuring project ':app-tests'.
> Exception thrown while executing model rule: android { ... } # app-tests/build.gradle line 16, column 5
> Could not find property 'manifest' on source set 'android test'.
Not completely sure this will work for your scenario, but you can update the root of the androidTest sourceSet like this
android {
sourceSets {
androidTest.setRoot('src')
}
}
There is also a test source set if it's just Java code, nothing Android specific.
You could also play around with the java.srcDir setting...
The above setting will look at these locations for your files.
<project>/<module>/src/AndroidManifest.xml
<project>/<module>/src/java
If you'd like to move both into the /src directory, you can use
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['src']
}
}
More Android Gradle details can be read at Configuring the Structure
You are welcome to debug these settings yourself with this setup
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['./src']
}
println "androidTest.manifest.srcFile = ${androidTest.manifest.srcFile}"
println "androidTest.java.srcDirs = ${androidTest.java.srcDirs}"
}
When you just clean the project, you'll see those lines being printed to the console
Instead of sources {} you should use sourceSets {} and the androidTest source set to customize the test source code location:
model { // Required for experimental plugin.
android {
sourceSets {
androidTest {
manifest.srcFile '../AppTest/AndroidManifest.xml'
java.srcDirs = ['../AppTest/src']
res.srcDirs = ['../AppTest/res']
assets.srcDirs = ['../AppTest/assets']
}
}
}
}
Note that this not not apply to unit test. For unit test (like with Robolectric), use the test source set.
It was tricky solution: to use experimental gradle plugin to compile native code with NDK and regular gradle plugin for test app.
build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
// experimental gradle plugin for the library to compile native code with NDK
classpath "com.android.tools.build:gradle-experimental:0.7.2"
// regular gradle plugin for the tests
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
subprojects {
task listAllDependencies(type: DependencyReportTask) {}
}
library gradle (experimental):
apply plugin: 'com.android.model.library'
...
model {
android {
...
ndk {
moduleName = "library-jni"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
stl = "c++_static"
abiFilters.addAll(['armeabi-v7a', 'x86']) // supported abis only
}
...
}
...
}
app/build.gradle (regular):
apply plugin: 'com.android.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion 9
targetSdkVersion 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
androidTest {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jni {
dependencies {
project ":library"
}
}
}
}
}
dependencies {
androidTestCompile project(':library')
androidTestCompile fileTree(include: ['*.jar'], dir: 'libs')
}
Related
I'm trying to use firebase-core library in my Android project but it keeps giving me this NoSuchMethodError in my released apk. However, it works fine in emulator. The exception message is this:
java.lang.NoSuchMethodError: No static method zza(Landroid/content/Context;)V in class Lcom/google/android/gms/common/zzc; or its super classes (declaration of 'com.google.android.gms.common.zzc' appears in /data/app/com.xxxx.xxxx/base.apk): com.google.android.gms.measurement.internal.zzfx.zzs(Unknown Source)
I added firebase-core:16.0.7 using Android studio's firebase assistant. And my gradle file is as follow:
buildscript {
repositories {
jcenter()
google()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
/**
* This line applies the com.android.application plugin. Note that you should
* only apply the com.android.application plugin. Applying the Java plugin as
* well will result in a build error.
*/
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
/**
* This dependencies block includes any dependencies for the project itself. The
* following line includes all the JAR files in the libs directory.
*/
dependencies {
compile 'com.google.firebase:firebase-core:16.0.7'
compile project(':Shared')
compile 'com.google.guava:guava:16.0.1'
compile 'joda-time:joda-time:2.10.1'
compile 'com.android.support:appcompat-v7:28.0.0'
compile files('libs/js.jar')
compile files('libs/gps-stripped.jar')
compile files('libs/antlr-runtime-3.2.jar')
compile files('libs/jackson-all-1.9.11.jar')
compile files('libs/logback-android-1.1.1-6.jar')
compile files('libs/slf4j-api-1.7.21.jar')
compile 'com.github.jsqlparser:jsqlparser:0.9.6'
compile files('libs/Android-Languages.jar')
androidTestCompile 'junit:junit:4.12'
}
/**
* The android{} block configures all of the parameters for the Android build.
* You must provide values for at least the build tools version and the
* compilation target.
*/
android {
compileSdkVersion 28
buildToolsVersion "26.0.3"
buildTypes {
release {
minifyEnabled false
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
}
debug {
minifyEnabled false
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
}
}
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')
}
packagingOptions {
pickFirst 'META-INF/license.txt'
pickFirst 'META-INF/LICENSE'
}
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
multiDexEnabled true
}
productFlavors {
}
}
Any clue on how to resolve this? Thanks.
I am developing an application which enabling Multidex in order to avoid 65k limit. I want to add an external library in Jar type (i.e. iPay Jar SDK). I've Synchronized the Gradle and succeed but I failed to run the project.
The error message shown like below
Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [/[dir]/app/build/intermediates/multi-dex/debug/allclasses.jar] (Can't process class [com/ipay/IpayAcitivity.class] (Unknown verification type [14] in stack map frame))
This is my Gradle Code
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName '[My Package]'
}
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile fileTree(dir: 'libs', include: ['*.jar'])
//Libs folder contains: org.apache.http.legacy.jar
//and ipay88_androidv7.jar
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.rey5137:material:1.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "[My Application Id]"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'build/source/apt/debug']
resources.srcDirs = ['src/main/res']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
beta {
resources.srcDirs = ['app/src/beta/res']
res.srcDirs = ['app/src/beta/res']
}
}
signingConfigs {
release {
...
}
}
}
Before I added this type of external library (i.e. iPay Jar SDK), the application was running successfully. But the problem arised after I had added iPay Jar SDK (second Jar Library).
For further information, I had already followed this guide on https://developer.android.com/tools/building/multidex.html
But it didn't work my project.
What's your suggestion to fix this error ?
Try this:
public class MyApplication extends MultiDexApplication
{
#Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext( base );
}
#Override
public void onCreate()
{
MultiDex.install(getTargetContext());
super.onCreate();
}
}
It seems your library is not compatible with Multidex. So you better update the library to the latest version(if an update is available). Or use only the required Google Play services API in your application and get rid off Multidex. Replace
compile 'com.google.android.gms:play-services:8.1.0' (the whole library)
this with something you use in your app like this
compile 'com.google.android.gms:play-services-ads:8.1.0' (library only for ads)
and remove this compile 'com.android.support:multidex:1.0.1'
You can find all the Google Play services API here https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
I created a project and I added the following to my build.gradle file, about which I got this error message A problem occurred evaluating root project NewsFeeder. Plugin with id android not found
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Is this your complete build.gradle ?
If so, you are missing
apply plugin: 'android'
usually above repositories block.
Also I think you need buildscript block to identify which gradle to be used.
Example build.gradle looks like
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v13:13.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
..... other configs .....
}
I have some build.gradle file this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
that throws this error :
A problem occurred configuring root project 'NewsFeeder'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find any version that matches com.github.chrisbanes.actionbarpulltorefresh:library:+.
Required by:
:NewsFeeder:unspecified
But, this reference to chrisbanes's actionbarpulltorefresh seems to be correct : https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-Stock. How can it be since in this project is available in [maven central repo][1] ?
For information, I set in some local.propertiesfile sdk.dir=/home/adt-bundle-mac-x86_64-20130522/sdk, which is the same that what echo $ANDROID_SDK returns
You need to tell gradle where it can look to find the dependency. If you want gradle to use the mavenCentral repository then add this to your build.gradle file:
repositories {
mavenCentral()
}
The buildscript repositories is just for the build script dependencies, not project dependencies. You want to add the repositories entry at the outer most, or project, level.
Your build.gradle would look like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
I receive this error :
Gradle: Execution failed for task ':Foo:dexDebug'.
And since 2day ! I have try a lot of solution... But nothing work fine ! Really ! Need Help !
I work with android Studio. (IntelliJ IDEA)
For this following three directory
FooProject [RootProject]
|-gradle
|-libraries
|-facebook [library1]
|-libs
|-android-support-v4.jar
|-res
|-*.(drawable...)
|-src
|-*.java
|-build.gradle
|-AnroidManifest.xml
|-facebook.iml
|-foosdk [library2]
|-res
|-*.(drawable...)
|-src
|-*.java
|-libs
|-YouTubeAndroidPlayerApi.jar
|-build.gradle
|-AnroidManifest.xml
|-foosdk.iml
|-Foo [project for execution]
|-libs
|-commons-io-1.3.2.jar
|-commons-lang3-3.1.jar
|-jackson-core-asl-1.9.11.jar
|-jackson-databind-2.1.4.jar
|-jackson-mapper-asl-1.9.11.jar
|-robospice-1.4.1-SNAPSHOT.jar
|-robospice-cache-1.4.1-SNAPSHOT.jar
|-robospice-spring-android-1.4.1-SNAPSHOT.jar
|-spring-android-core-1.0.1.RELEASE.jar
|-spring-android-rest-template-1.0.1.RELEASE.jar
|-YouTubeAndroidPlayerApi.jar
|-src
|-main
|-java
|-*.java
|-res
|-*.(drawable...)
|-build.gradle
|-AnroidManifest.xml
|-Foo.iml
|-gradlew
|-gradlew.bat
|-local.properties
|-settings.gradle
|-RootProject.iml
I have for my settings.gradle
include ':libraries:facebook', :libraries:foosdk', ':foo'
For the files "build.gradle" :
For libraries/facebook/build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For libraries/foosdk/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For Foo/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':libraries:foosdk')
compile project(':libraries:facebook')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src']
res.srcDirs = ['src/main/res']
}
}
}
Is your Foo project in /Foo or /foo folder (note the upper case)? You may need to correct the include 'foo' to 'Foo'?
If that doesn't work, please paste the info or debug output of your Gradle build. If you're running AndroidStudio and don't have any output, go to the root of your project and run gradlew.bat assembleDebug --info (on Wins) or ./gradlew assembleDebug --info (on Linux/Mac) or --debug and paste the output here so we can see what went wrong exactly.