Android Studio 1.3 : Test Module is not coming in Module window - android

I update android studio in 1.3.2. and gradle plugin is also 1.3.0
but on clicking file -> New -> Module. Window is opening but the recent update in android studio test module is not showing

You can create manually a structure like
root
app
build.gradle
testmodule
build.gradle
build.gradle
settings.gradle
Create a folder, for example testmodule.
In testmodule create:
testmodule
build.gradle
src
main
java
com.mycompany.package.test
In testmodule.build.gradle you can do something like:
apply plugin: 'com.android.test'
android {
compileSdkVersion XX
buildToolsVersion = '23.0.0'
defaultConfig {
minSdkVersion ...
targetSdkVersion ..
// The package name of the test app
testApplicationId 'com.mycompany.package.test'
// The Instrumentation test runner used to run tests.
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
// Set the target app project. The module specified here should contain the production code
// test should run against.
targetProjectPath ':app'
targetVariant 'flavor1Debug'
}
dependencies {
// Android Testing Support Library's runner and rules and hamcrest matchers
compile 'com.android.support.test:runner:0.3'
compile 'com.android.support.test:rules:0.3'
compile 'org.hamcrest:hamcrest-core:1.3'
}
In settings.gradle add the module.
include ':app'
include ':testmodule'
Make sure to use the plugin 1.3 and gradle 2.5
In your top-level build.gradle
classpath 'com.android.tools.build:gradle:1.3.0'
In your gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

Related

The module 'app' is an Android project without build variants

I am getting below error while importing android project.
Error:The module 'app' is an Android project without build variants, and cannot be built.
Please fix the module's configuration in the build.gradle file and sync the project again.
Gradle file code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.djalel.android.bilal"
minSdkVersion 9
targetSdkVersion 25
versionCode 4
versionName "1.3"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
aaptOptions {
cruncherEnabled = false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.3.1'
implementation 'com.android.support:support-v4:25.3.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'com.jakewharton.timber:timber:3.1.0'
}
repositories {
mavenCentral()
}
I checked with working gradle file as well but getting same error in this project.
Above gradle file code seems to be perfect. Probably its nothing to do with app/build.gradle (Module:app). Just open other build.gradle (Project:Android) file in Project window and verify your Android Studio version it must be same as yours.
I replaced from:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
to my Android Studio v3.0.1 in my case:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Press "Try Again" to Sync gradle file. This resolved my problem with a successful build.
For me, this issue appeared when I updated Android Studio to version 3.3.
Disabling experimental feature "Only sync the active variant" fixes it:
Try use command line to run gradlew tasks to see why the build would fail.
In my case:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
So I just ran Go to Android\sdk\tools\bin sdkmanager --licenses to accept licenses and then the build passed in command line.
I think Android Studio is crying for the wrong issue. So you may check the real output in command line and find what is happening.
Just install the Android SDK platform package through SDK Manager in Android Studio, relevant to your Compile SDK version. It will prompt you to install the package as well as to accept the license. After that just sync the gradle, it will resolve the issue.
You must update your dependencies in build.grade in the buildscript block:
classpath 'com.android.tools.build:gradle:3.1.0'
to:
classpath 'com.android.tools.build:gradle:3.4.2'
If this error occurs for other module than 'app'
Remove gradle variable from that module's build.gradle like
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
& replace it actual value
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
Clean Project -> Rebuild Project
I had this issue in my library project. I solved it by adding
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
To the beginning of build.gradle

no test task in gradle build

I am trying to build and imported Android project in Android Studio/Eclipse.
My goal is to write automated test to the current project. First, I am trying to build the project and then to make an apk file of it so I will be able to execute real device/emulator tests on it.
Here are my available Gradle tasks
There is no build or test or assemble and etc. tasks which are I am looking to use so I will reach my goal.
Here is my project tree and both build.gradle files
`
apply plugin: "java"
repositories {
jcenter()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.13
testCompile 'junit:junit:4.12'
}
and
apply plugin: 'com.android.application'
version = "1.2"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "sdk.mobfox.com.appcore"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
archivesBaseName = "MobFox-Android-SDK-Client-" + version + ".apk"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize = "4g"
}
lintOptions {
abortOnError false
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-ads:11.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.danikula:videocache:2.7.0'
testCompile 'junit:junit:4.12'}
I tried to open the project in Android Studio but got the same state.
I opened a new Gradle project in Eclipse and saw that the tasks I am looking for are available there - I believe because of the 'java-library' plugin which added to the build.gradle root file but I use the same plugin in my root build file and did not receive what I expected.
I was succeeded to execute the Gradle "tasks" which gave me the next response in console :
Working Directory: C:\Users\orit\Desktop\mobFox\MobFox-Android-SDK-master\MobFox-Android-SDK-master
Gradle User Home: C:\Users\orit.gradle
Gradle Distribution: Specific Gradle version 4.1
Gradle Version: 4.1
Java Home: C:\Program Files\Java\jdk1.8.0_91
JVM Arguments: None
Program Arguments: None
Gradle Tasks: tasks
:tasks
All tasks runnable from root project
Build tasks
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
Build Setup tasks
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.
Documentation tasks
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
buildEnvironment - Displays all buildscript dependencies declared in root project 'MobFox-Android-SDK-master'.
components - Displays the components produced by root project 'MobFox-Android-SDK-master'. [incubating]
dependencies - Displays all dependencies declared in root project 'MobFox-Android-SDK-master'.
dependencyInsight - Displays the insight into a specific dependency in root project 'MobFox-Android-SDK-master'.
dependentComponents - Displays the dependent components of components in root project 'MobFox-Android-SDK-master'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'MobFox-Android-SDK-master'. [incubating]
projects - Displays the sub-projects of root project 'MobFox-Android-SDK-master'.
properties - Displays the properties of root project 'MobFox-Android-SDK-master'.
tasks - Displays the tasks runnable from root project 'MobFox-Android-SDK-master'.
Verification tasks
check - Runs all checks.
test - Runs the unit tests.
Rules
Pattern: clean: Cleans the output files of a task.
Pattern: build: Assembles the artifacts of a configuration.
Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
**1. What is the reason I cannot get all the task I got when I open a new project?
How can I add these tasks so I will be able to create apk file, build and execute integration tests?**
task, you write in project level build.gradle file. See below pic for the reference.
You are posting module level build.grale file.
Applying com.android.application should be enough, you should not apply java plugin on the root either and add dependencies there.
Operate on your app project, with Java specific stuff.
For more reference how to structure your project.
https://developer.android.com/studio/build/index.html

Android Studio Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'

I installed Android Studio and when I try to import a project from gradle this resolve error shows up:
Unable to load class
'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
I deleted the files in my Users .gradle folder and tried different gradle versions. I don't know how to fix this.
This page might help solve the problem. What they say is:
So we leveraged this version to add a new artifact, named
groovy-backports-compat23. This artifact shouldn’t be necessary for
most of you, but if you face an error like:
Caused by: java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling at
java.net.URLClassLoader$1.run(URLClassLoader.java:372)
in your project, then it means that a class has been compiled with
Groovy 2.3+ but that you are trying to use it with an older version of
Groovy. By adding this jar on classpath, you give a chance to your
program to run. This may be particularily interesting for Gradle users
that want to use a plugin built on Gradle 2+ on older versions of
Gradle and face this error. Adding the following line to their build
files should help:
buildscript {
// ...
dependencies {
classpath 'some plugin build on gradle 2'
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
} }
Note that for now, this jar only contains the ShortTypeHandlingClass.
Future versions may include more.
- See more at: http://glaforge.appspot.com/article/groovy-2-3-5-out-with-upward-compatibility#sthash.mv7Y8XQv.dpuf
I can fix this error message using these three methods.
use latest gradle version
use latest android SDK and tools.
use proguard-rules.pro
build.gradle (Project:xxxxx)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
mavenCentral()
}
}
build.gradle (Module:app)
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I had the same problem. I ran gradle from command line and that did work.
After that, I found File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. There "Use local gradle distribution" was active. Changed it to "Use default gradle wrapper (recommended)" and it worked.
I have had a same problem. And I have found a solution.
Cause
This problem is caused by android gradle plugin does not match for gradle version.
Solution
Edit build.gradle in project. gradle plugin version must be satisfied requirements for android studio.
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
And edit distrubutionUrl in gradle/wrapper/gradle-wrapper.properties. version of gradle must be satisfied requirements for gradle plugin.
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
You can find version compatibilities between android studio, android gradle plugin and gradle in this page
https://stackoverflow.com/a/29695756/3675925

Import Facebook SDK on Android Studio 0.5.1

I've been searching around for a while now and tried every answer I could find with no success. I am starting to believe that the problem is in the android studio version.
However here is what I've done:
1 - I've downloaded the facebook sdk
2 - Copied the sdk into my libs folder so the project looks like
following:
MyProj
-app
--libs
---facebook
----build.gradle (2)
--build.gradle (1)
-settings.gradle
3 - I modified settings.gradle:
include ':libs:facebook', ':app'
4 - I modified build.gradle (1) to:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'me.dm7.barcodescanner:zxing:1.0'
compile 'com.koushikdutta.ion:ion:1.2.4'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.squareup.picasso:picasso:2.1.1'
compile project(':libs:facebook');
}
5 - Lastly edited build.gradle (2):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Now when syncing I get the annoying warning:
Gradle 'MyApp' project refresh failed:
Configuration with name 'default' not found
And I am not able to use the facebook library.
I guess I'm doing something wrong with the gradle files. Any ideas?
On Mac with Android Studio 0.5.8, this is what worked for me:
Click on the top level project and select project structure:
Click the + to add another module
Click on "Import Existing Project" and "Next"
Select the facebook directory from your SDK folder and click next
The facebook module should now be shown in addition to your existing module
Click on your project, select the Dependencies tab and click '+' to add a dependency.
Select "Module Dependency" as dependency type.
Select the Facebook module that we just added
Note that it shows up under dependencies (of your app)
And you're all set!
The directory structure of your project doesn't match the dependency specs you're using; it's not clear what's in your settings.gradle. That error you get with "Configuration name 'default' not found" is terribly unintuitive, but it's the message you get when Gradle is looking for a module in a certain directory and it's not finding it. If you have a dependency spec (and settings.gradle include) like :libs:facebook, it will look in MyProj/libs/facebook, not MyProj/app/libs/facebook where you've placed it.
I would recommend this structure:
MyProj
-app
--build.gradle (1)
-libs
--facebook
---build.gradle (2)
-settings.gradle
i.e. move the libs directory one level up so it's alongside app directory instead of underneath it.
Your settings.gradle file should be:
include ':app', ':libs:facebook'
(which is probably how you already have it set up) and a dependency on facebook should look like:
compile project(':libs:facebook')
(also like how you already have it set up)
Follow this step to add Facebook SDK to your Android project.
1) Open your fresh Android project
2) Go to File -> Project Structure (or) Alt+Ctrl+Shift+S
3) Go to module click + on second row of window then import module
4) After Facebook SDK imported click + on third row and select Module Dependency select Facebook SDK Apply and press ok
I made a Facebook Module version from scratch https://github.com/cesarferreira/Facebook-Module
If you want to use this module for your projects you should follow the next steps:
You should create a new 'libs' folder in your project root
You should copy this project into the 'libs' folder, you must manually copy the project, because if you copy it using the drag and drop action the project doesn't work because android studio throw an error
Add the next line into settings.gradle file: include ':libs:facebook'
You should rebuild the project
THAT'S IT!

Android Studio and Gradle - build fails

I am building a small library project along wit a sample project to illustrate the use. I can't manage to run the sample in Android Studio. I have created the project from scratch. I am experienced with Eclipse but it's my first try at Android Studio & Gradle.
The error given:
Gradle: Execution failed for task ':demo:dexDebug'.
Running C:\DevTools\Android\android-studio\sdk\build-tools\android-4.2.2\dx.bat
failed. See output
I have the following folder structure:
- demo
- build
- libs
- android-support-v4.jar
- src
- main
- java
- res
- build.gradle
- library
- build
- libs
- android-support-v4.jar
- src
- main
- java
- res
- build.gradle
- build.gradle
- settings.gradle
Build.gradle at project root:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
Settings.gradle at project root:
include ':library', ':demo'
Build.gradle for the library module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Build.gradle for the sample module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile project(':library')
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Specifying compile files('libs/android-support-v4.jar') means that every library includes support v4. What you want to do is just specify that every library depends on it:
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
This will allow gradle to detect all dependencies and include this only once.
Note: You have to first use the SDK Manager and download and install two Maven repositories: "Android Support Repository" and "Google Repository".
I found the problem:
I removed that line from the sample gradle file.
compile files('libs/android-support-v4.jar')
However, I have no idea why this does not work (if I have 2 or 3 external libraries that all depend on the support library, how are we supposed to do, without touching their gradle files?
You should navigate to your libs folder in the IDE, right click on the jar and select to add the library to the project, it still needs to establish the dependency even though the jar appears to be there. Also look at your gradle built script to make sure the dependency appears there. If that still doesnt work just run a gradle clean on the project. Intellij documentation will give you more details on what clean does. see:
stackoverflow gradle build
This error could be encountered while migrating from Groovy to kotlin DSL as well and here are the steps to get rid of it:
If you are still in the process of migrating please complete the migration of gradle files first, use kts syntax and then sync gradle files.
Use this dependency inside your build.gradle(app level):
implementation("androidx.legacy:legacy-support-v4:1.0.0")
Remove id("kotlin-android-extensions") from plugins block inside build.gradle.kts (app level).
That's it! 3rd Point solved the issue for me but trying all the points should definitely fix the issue.
In my Case replace this line
classpath "com.android.tools.build:gradle:7.0.2"

Categories

Resources