I ran into this problem after i updated android studio and the gradle version. Here's what i did step by step:
First i got the following error:
Build Gradle Error Could not get unknown property 'compile'
I checked stackoverflow and it said that changing "compile" with "implementation" would solve the problem, and so i did that.
Another issue was that maven was deprecated. So i used, maven-publish instead of maven.
Now i am getting the following error:
12:24 PM Gradle sync failed: Could not find method uploadArchives() for arguments [build_a5ye7ixpcm9qfmol93kt3ucl1$_run_closure4#73b8042a] on project ':expo-application' of type org.gradle.api.Project. (17 s 537 ms)
In this part of code in build.gradle(:expo-application):
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
I am not really familiar with android studio or java. I just use Android Studio for configuring react native apps for android. Can someone please help me resolve these issues..
Thank you
As of Gradle 7.0, compile has been removed in favor of api. When you changed compile to implementation, you effected the transitive properties of the libraries. I'm not sure where you read that changing compile to implementation was the correct answer, but it isn't. api is a much closer approximation to compile. This chart gives a fairly easy to understand explanation of why this is. You should change the implementation to api and make sure you are using the java-library plugin instead of the java plugin. This should allow gradle to see the UploadArchives method. However, this wil cause a new issue.
As of Gradle 6.0, UploadArchives is also deprecated along with the maven plugin. You should consider using the maven-publish plugin instead. This will ensure your build continues to work in future Gradle releases.
So, to summarize, make sure your plugins look like this
apply plugin: 'java-library'
apply plugin: 'maven-publish'
and update your code to use publishing instead of UploadArchives. More information on this can be found in the current Gradle user guide here.
Alternatively, you can downgrade your gradle version to something before 7.0 and just ignore all the deprecation warnings. The choice is yours.
http://www.tutorialspoint.com/junit/junit_environment_setup.htm
I have done everything like in this step by step tutorial and still when I try to write the line
import org.junit.*;
The "junit" part is lighten red and the error message is "cannot resolve symbol "junit"".
The tutorial you are following seems to be written for command line usage. (Download jar, set classpath etc). So the same wouldn't work in IntelliJ.
IDEs actually make these a lot easier.
To solve your current dilemma, try this. Place the cursor on the red 'junit' (which is basically a broken import) and choose "Add Junit4 to classpath". This will add the necessary junit jars that IDEA ships with to your classpath.
Open up your build.gradle and make sure JUnit is there
dependencies {
testCompile 'junit:junit:4.12'
// other dependencies...
}
And for a better link for Android-specifics, read Getting Started with Testing from the Android docs.
I feel dumb for even having to ask this, but I can't find an answer anywhere. I'm trying to write simple unit tests that test static methods from my Android app and I've already added
// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
To my app build.gradle file, but org.junit.test annotations or anything related to Junit4 will NOT resolve. There is no "Unit Test" build variant either.
Can anybody assist me? Thanks.
looks like you have not download dependencies:
try run "gradle build"
or sync gradle project if your IDE has this option
I have 2 modules: A and B.
-A is a standalone module. Its tests run just fine all by itself.
-B is a dependent module. Its tests require a certain file in A's test folder (one test file in B extends one in A)
Here are what I believe to be the relevant parts of B's build.gradle:
android {
...
sourceSets {
test.java.srcDirs += "../A/src/test/java"
}
}
dependencies {
compile project(':A')
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-core:1.9.5'
}
While this technically works for what I need it - it has the nasty side effect that whenever I run A's unit tests, they also run all of B's tests. I would really like if this was not the case.
I am using Android Gradle 1.1 (along with Android Studio 1.1), and I think this is causing me some issues. I have tried all the solutions I could find - unfortunately, none of them seem to apply for Android Gradle 1.1 - for example:
Removing the sourceSets from B's build.gradle and adding (to B's dependencies) the line
testCompile project(':A').sourceSets.test.output
Produces the build error Could not find property 'test' on SourceSet container.
Am I going about this the wrong way? Is there an easier/better way to include test files across modules? I'm pretty new to Gradle/Android Studio, so it's totally possible I'm missing a dead obvious solution.
Check all your modules by tree using command:
gradle projects
It will list all your project modules and you can see if you are configuring your sub projects in a right way. Also run command:
gradle --gui
It will list all the tasks for all modules, and you can always run one module independently from other e.g.
gradle A:tasks
gradle A:test
gradle B:test
OR both
gradle A:tasks B:test
Note: You do not need to specify the A if it is the root project and B,C,D sub-modules but for submodules you need to specify it. When you do:
gradle --gui
You can double click on any task to see how it runs and you can do the same manually from command line. Hope this helps
First and foremost, I am aware of the existence of this question - How do I add a library project to Android Studio? - and unfortunately, it has not helped me.
My goal is rather simple. I want to write an Android app using the Android Studio IDE (0.2.11), and the Guava libraries in my code.
I do not know Gradle, I've only started using Android Studio and my Visual Studio/C# background has dumbed me down, for which I apologize (in that Mickey Mouse world, you typically just add a library reference and off you go).
I will document my steps with screenshots. I mostly followed advice given in this answer.
I created a libraries folder under my project folder.
I cloned Guava repository into it.
Files successfully appeared.
I went to Project Structure and selected Import Module.
I selected Create module from existing sources and agreed to all the default choices.
I updated my settings.gradle file to include ':libraries:guava', ':Test':
And my build.gradle file with compile project(":libraries:guava"):
But all I'm getting whenever I'm trying to rebuild the project is:
Error: Gradle: A problem occurred configuring project ':Test'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
I did try putting a build.gradle as below in the guava folder:
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.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
(as the aforementioned answer says).
I have googled up and down to find the "correct" build.gradle for Guava.
https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild - didn't help me, either.
I did try countless things which I will not describe here as they were rather haphazard - I tried adding a module dependency, I tried turning Use auto-import on in Gradle settings, etc.
I know it's not a way of solving issues and I promise I will diligently read Gradle's User Guide from 1 through 5.4.2 to 7.3, but I can't believe this is really prerequisite to achieve something as unremarkable as merely adding a library to a project? Why is there no default build.gradle file from which one could start to fiddle with all sorts of things if necessary?
And the real question - how do I create an app (in Android Studio) that builds, actually runs on an Android device and on the top of that allows me to use Guava so I could sort a map by values without writing 50 lines of code? :)
Sorry about the chatty tone of my question, I know the drill around here, it's just my way of venting my frustration off.
Judging by how many votes were casted for questions and answers that tackled similar issues, I'm sure I'm not the only one who would benefit from some more instructions. I would start a bounty on it straight away, but the rules forbid me.
If you just need to use a stable, released version of the Guava libraries, importing it is extremely easy.
Just go to the build.gradlefile of the module where you want to use the library (i.e GuavaTestProject/GuavaTest/build.gradle) and, right after
repositories {
mavenCentral()
}
add a Maven dependency:
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '15.0'
}
Rebuild your project if needed and that's all (tested right now with a fresh project created with Android Studio 0.2.13).
If you really need to include the source code of the Guava library and compile it yourself as a module of your Gradle build that's an entirely different problem because Guava is build with Maven and so you need to move the Guava build system from Maven to Gradle, which I think is overwhelmingly complex for your goals.
If you just need to browse the source or view it while debugging, what I would do is:
Download Guava source code on a separate folder:
git clone https://code.google.com/p/guava-libraries/
git checkout v15.0
When Android Studio doesn't find the sources, click on "Attach sources" and point to this alternative location.
I think if you don't need to actually modify and compile Guava source code this is the easiest solution.
dependencies {
compile 'com.google.guava:guava:19.0'
}
Source: https://github.com/google/guava
EDIT:
As of v22, there's specific guava version for Android.
dependencies {
compile 'com.google.guava:guava:22.0-android'
}
* Thanks Sam :)
Thats a lot of info in your question.
I am using Guava too. But I don't remember going through any of this trouble..
Guava is available on the mavencentral. So adding guava to your project should be fairly simple. AFAIK, you do not need to checkout, build and add a project dependency etc..
See gradle file for my app below.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
// Dependencies
dependencies {
compile fileTree(dir: 'libs', include: '*.jar') // jar files under the libs folder.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // actionbarsherlock,
compile 'com.android.support:support-v4:18.0.0' // android support lib
compile 'com.google.code.gson:gson:2.2.4' // google GSON
compile 'com.google.guava:guava:14.0.1' // guava 14.0.1
}
do not use the full guava library, use the version specific for android,
dependencies {
compile 'com.google.guava:guava:23.0-android'
}
In Android Studio 0.3.0 This is now working as it should on Mac. See the release notes for additional options in adding libraries
http://tools.android.com/recent/androidstudio030released
I have been working on Windows now and there are two options
Right click on a jar in libs and you have an add to library
Or you can push F4 and get to open library settings so it seems you do not have to struggle as much on Windows as on a Mac
This is what I did. Please read to the end since it works inconsistently and if you do not see the blue arrow first try there is a resolution. First I created a libs folder. I do not think this is needed though but it is a habit.
First try go to File , Project Structure.
If you see a little blue arrow at the top left push it and you will go to the screen where you can add a library
If you manage to get to this screen below push the plus sign and add the library.
You may also see a red line at the bottom saying Guava not used with a light bulb. This fill add the dependancy to the Gradle Build File
IF YOU DONT SEE THE BLUE ARROW
GO instead to File, Other settings, Default project structure.
From that screen you can add the library
Then go back to project structure and add it. The thing is that it will remain as a default for all your projects so you can add and remove it for each individual project via the project structure menu. I am not sure if this is a bug in Android Studio the fact that you can be blocked from adding it to the individual project without changing the default.
For Android Studio 3.2.1:
Click the File/Project Structure menu (ctrl+alt+shift+S). Press the + button in the Dependencies tab from the app menu to add a Library dependency.
Look for com.google.guava:guava:(whatever number is the most recent one) and add it.