How to add Android Studio plugin as dependency in Gradle? - android-studio

I installed the TestNG plugin through Android Studio. On my filesystem the following files were installed:
C:\Program Files\Android\Android Studio\plugins\testng\lib\testng.jar
C:\Program Files\Android\Android Studio\plugins\testng\lib\testng-plugin.jar
C:\Program Files\Android\Android Studio\plugins\testng\lib\resources_en.jar
C:\Program Files\Android\Android Studio\gradle\gradle-2.2.1\lib\plugins\testng-6.3.1.jar
I added the the TestNG dependency to the build.gradle of my Module--not "Project":
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
testCompile 'testng:testng:6.3.1' // Added this line
}
But Gradle couldn't find the library:
Error:Gradle: A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugUnitTestCompile'.
> Could not find testng:testng:6.3.1.
Searched in the following locations:
https://jcenter.bintray.com/testng/testng/6.3.1/testng-6.3.1.pom
https://jcenter.bintray.com/testng/testng/6.3.1/testng-6.3.1.jar
file:/C:/Users/UserFoo/AppData/Local/Android/sdk/extras/android/m2repository/testng/testng/6.3.1/testng-6.3.1.pom
file:/C:/Users/UserFoo/AppData/Local/Android/sdk/extras/android/m2repository/testng/testng/6.3.1/testng-6.3.1.jar
file:/C:/Users/UserFoo/AppData/Local/Android/sdk/extras/google/m2repository/testng/testng/6.3.1/testng-6.3.1.pom
file:/C:/Users/UserFoo/AppData/Local/Android/sdk/extras/google/m2repository/testng/testng/6.3.1/testng-6.3.1.jar
Required by:
MyBlackjack2:app:unspecified
How do I add TestNG to the search path? On the other hand, Android Studio installed the plugin in that location for a reason, but what's the best way to include it in my project?

Use TestNG 6.9.4, which is distributed on both JCenter and Maven (6.3.1 is on Maven Central only, which you don't seem to have in your repositories list).

Related

How to fix "Unable to load class 'com.android.builder.errors.EvalIssueReporter'." error on Android Studio 3.2.1

I use IntelliJ IDEA for creating #Flutter projects and I have the Android Studio for installation purposes of Flutter onto my machine. The problem arose when I upgraded the Android Studio from 3.1.4 to 3.2.1. Moreover, after this upgrade, I'm no longer able to create any project in both IDEs.
The error message in IntelliJ
The error message in Android Studio
P.S. Those are the default programs of both IDEs namely, IntelliJ and Android Studio.
any newly-created project brings up this error; however, previously-created projects work perfectly fine.
My machine has 64-bit OS, x64-based Processor
IntelliJ
IntelliJ IDEA 2018.3.3 (Community Edition)
Build #IC-183.5153.38, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Android Studio
Android Studio 3.2.1
Build #AI-181.5540.7.32.5056338, built on October 9, 2018
JRE: 1.8.0_152-release-1136-b06 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
project's build.gradle file:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
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
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
the individual module build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.nonna.myapplication"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
}
I have checked those questions but unfortunately, the error wasn't fixed.
Build errors after Android Studio 3.2.1 upgrade
Could not find com.android.tools.build:aapt2:3.2.0
This issue got solved and now the IDE is working like a charm.
As it was seen from the provided screenshots there was an error in the Android Gradle plugin, so to solve this issue follow the numbered steps in the newly provided screenshots below.
(Part 1) Solving gradle issue due to upgrading Android Studio to 3.2.1
Step 0: From the left panel in your IDE, choose the android
[name_of_project] folder
Step 1: look for the build.gradle file then double click it to
start editing it
Step 2: change exactly the line that states
classpath
'com.android.tools.build:gradle:3.2.1' to the current version of
your Android Studio, in other terms, classpath
'com.android.tools.build:gradle:3.3.0' in my case.
(Part 2) Solving gradle issue due to upgrading Android Studio to 3.2.1
Step 3: After finishing from Steps 1 & 2, go to the gradle folder
Step 4: Double click on the wrapper subfolder
Step 5: Click the gradle-wrapper.properties file to start editing
it
Step 6: make sure that your gradle version is compatible with your
current Android Studio
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
The Android Gradle plugin 3.3.0 requires the Gradle version of 4.10.1 and newer.
Disclaimer: you need to do these steps whenever you create a new project on whatever IDE you use namely, Android Studio, IntelliJ IDEA, and VS Code.

Download and commit gradle dependencies and plugins in Android Studio

This is an excerpt from a build.gradle file for one of my modules. I'm using android-studio-1.5.1 and gradle 2.10.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
I also have classpath 'com.google.gms:google-services:3.0.0' in the project level build.gradle file.
I'm trying to gather all the associated jars into a directory which I can commit to my git repo. Something like:
task copyRuntimeLibs(type: Copy) {
into "${projectDir}/libs"
from configurations.compile
}
(This does not work)
Also, I'm not trying to download the sources or javadocs.
I need to be able to commit all dependencies so that the project can be shared on an intranet without internet access.
I've written a plugin which will download all jars and poms. See the code here to download all jars and all poms from a Gradle Configuration
Note: There's a failing test here which shows that the parent pom's are not being downloaded. I've raised an issue here on Gradle's github.
I will likely improve the plugin to invoke the Maven Model Builder APIs to get the parent poms.
FYI - I've already integrated the ModelBuilder APIs successfully with Gradle (see here and here) so shouldn't be too difficult.

Some gradle issue after updating Android Studio to v2.0

I have updated Android Studio, and when opening a project done in the 1.5 version this is the error I am getting:
Error:Failed to open zip file. Gradle's dependency cache may be
corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires
network)
The following is my dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
}
I faced the same issue when I updated my android studio to 2.2.3 from 2.1.
After a while of struggling, went project->right click -> open module settings->project
1) Gradle : 2.14.1
2) Android plugin version : 2.2.3
3) Android plugin repository : jcenter
4) Default library repository : jcenter

Gradle - build jar which includes both .class and .java files?

I'm using android studio + gradle. I have a module that is a plain standalone java app. Is there a way I can package that module into a .jar file that includes both its compiled .class files, and its source .java files? By default it looks like android studio is only including .class files for me.
I was originally doing this using Eclipse (export as a jar), but can't figure out how to do the equivalent with android studio.
---- EDIT -----
This is my current build.gradle file, but it still outputs a jar that only includes the .class files:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
task sourcesJar(type: Jar) {
from sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
Thanks
It is most common to publish a separate sources JAR from compiled classes.
To do that in Gradle, add this to your Gradle build:
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}

Android studio build script error,unsupported gradle DSL method found : android()!

I upgraded the Android Studio to AS 0.6 then imported the project developed in AS 0.3
I am getting errors like:
Build script error,unsupported Gradle DSL method found : android()'!,
Possible causes could be:
- you are using Gradle version where the method is absent
("open_gradle_settings">Fix Gradle settings</a>)
- you didn't apply Gradle plugin which provides the method
(Apply Gradle plugin)
or there is a mistake in a build script (Goto source)
I changed my dependencies path in build.gradle to:
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 14
}
What might the problem?
Is there any guide which tells how to upgrade the project?
Actually it stated in the error message. So just add
apply plugin: 'com.android.application'
between dependencies section and android section
Think of “Gradle DSL method” as a Java method. So in Gradle, methods can be distinguished by either {} or “.”. So
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
is the same as
dependencies.compile fileTree(dir: 'libs', include: ['*.jar'])
where both “dependencies” and “compile” are methods.
So you are including a method somewhere in your build.gradle file that is not supported by your program. For example, make your dependencies this:
dependencies {
nothing 'this.does.nothing.build:gradle:0.7.+'
}
Which is the same as writing:
dependencies.nothing 'this.does.nothing.build:gradle:0.7.+'
And you will see an error saying “unsupported Gradle DSL method found: ‘nothing()’!”
Obviously "nothing" is not a real method. I just made it up.
So one of your "android" methods is wrong.

Resources