Is commenting junit test in Android Studio a safe way? - android

I recently migrated from Eclipse to Android Studio and I'm using Android Studio 1.5.1. Before when I started Android Studio, I got this error:
Failed to resolve: junit:junit:4.12
After searching in Google and trying some proposed options, only commenting junit test in app/build.gradle solved the problem:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
}
But I want to know is this a good and safe option to resolve that problem? For example does it cause any problem in future?

You will need to add the following to your build.gradle file and it should work fine.
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}

Related

Unresolved dependencies: com.android.support.constraint:constraint-layout:1.0.1

I downloaded Android Studio for the first time and encountered a problem:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
On a another dock appeared:
ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.0.1
Show in Project Structure dialog
Affected Modules: app
Where and how can I resolved the issue?
I believe the error is with constraint-layout:1.0.1 but I can't seem to find solution else where.
You should connect to internet and sync project with gradle and gradle will download neccessary files.if you have problem to connect to the internet to download gradle, you can set http proxy this way :
File->Settings->search for Proxy->select Manual proxy configuration->HTTP
Host name:[yourHost] Port number:[yourPort]
you need to change the Host name to the proxy you use
ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.0.1 Show in Project Structure dialog Affected Modules: app
It's probably because incompatibility with the recent Android Studio. You can try using version 1.0.2 with:
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
don't forget to add the google() maven to your build.gradle.
See the artifacts at https://mvnrepository.com/artifact/com.android.support.constraint/constraint-layout
But, you should consider upgrading your project to AndroidX. See Migrating to AndroidX.

Javapoet not found in processor

I created an Android library that uses JavaPoet to generate classes. It works well on my local workspace ; even if I include the library module into another project.
Now I'm trying to put my project online through bintray. The project is uploaded correctly, but then when I include it in a new project and build the projet I get this message :
Error:Bad service configuration file, or exception thrown while
constructing Processor object: javax.annotation.processing.Processor:
Provider me.aflak.filter_processor.FilterProcessor could not be
instantiated: java.lang.NoClassDefFoundError:
com/squareup/javapoet/TypeName
I guess it comes from the way I manage the dependencies... Compiletime, Runtime stuff...
This is processor build.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':filter-annotation')
api 'com.squareup:javapoet:1.9.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.google.auto.service:auto-service:1.0-rc3'
}
This is annotation buid.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.8.1'
}
This is how I include the library in an empty project :
// build.gradle project
repositories {
maven{
url 'https://dl.bintray.com/omaflak/maven'
}
}
// build.gradle module
dependencies {
compile 'me.aflak.libraries:filter-annotation:1.0'
annotationProcessor 'me.aflak.libraries:filter-processor:1.0'
}
Could someone point me out to the right direction ? Thanks !
I finally got the solution (a bit randomly though :p).
I had to add mavenLocal() in the library module.

adding json dependency to a library module in android studio

I created a new library module to my project in Android Studio. A class in this new module accesses org.json.JSONObject.
I'm getting the error:
failed to resolve org.json:json:20141113
when trying to build the project.
Here's how my build.gradle file looks:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':app')
compile files('libs/volley.jar')
compile 'org.json:json:20141113'
}
Please let me know if I'm missing anything.
Thanks.
Try adding a repository to your configuration maybe that helps.
repositories {
mavenCentral()
}
For more information see here:
User-guide: Dependency Management Basics
Test This one , Worked for me
dependencies {
implementation 'com.cedarsoftware:json-io:4.10.1'
}

Why can't I add Facebook SDK on Android Studio?

I am following the Getting Started, Facebook Android SDK.
But when I am adding the repositories and the dependencies, I get the following error:
Error: Module version com.facebook.android:facebook-android-sdk:4.1.0 depends on libraries but is not a library itself.
I tried with several versions of the SDK but I can't make it work.
This is how my gradle looks:
dependencies{
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
repositories{
mavenCentral()
}
I am using the BuildTools 22.0.1
I hope someone can orient my with this issue.
Regards
compile 'com.facebool.android:facebook-android-sdk:4.1.0' Is the facebool correct or is that an error? If that's an error then that could be your issue. Also if you can't get it to compile from a maven source try downloading a jar and putting it in your local library. Then go into the project structure and go to the module you want to add this library to and click on the dependencies tab and there is a plus icon to add a library from file.
In you build.gradle(Project:Your-Project-Name) replace jCentral() with mavenCentral() in both (allproject/repos and buildscript/repos) then sync your gradle.
Hope this helps.

Android Studio - MavenCentral dependency sync ok, but symbol cannot be resolved

So, I managed to create an Android library component and publish it on Maven Central. But when I'm trying to use it as a dependency in a new project, Android Studio can't seem to find the classes.
build.gradle for the app module:
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'no.hyper:libdateintervalpicker:1.0.0' //this is the one I want to use
}
This part seems to work, at least I get no sync errors. However, when trying to access to package and classes from my MainActivity, Android Studio can't find them and gives me "cannot resolve symbol" message.
I have tried downloading the classes.jar from the archive directly from Maven Central, and they are indeed in the package.
Other dependencies seem to appear in the /build/intermediates/exploded-aar folder after syncing, but that does not happen to my library.
I use Android Studio 1.0.2 on OSX 10.9.5 (Mavericks)
Any suggestions?
Looking in your pom, it states <packaging>aar.asc</packaging>. It should be aar instead.
Oh, and the answer to actually being able to use the library, was to add #aar to the dependency so that it now reads
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'no.hyper:libdateintervalpicker:1.0.0#aar' //note the magic #aar
}
Edit:
Removing the block
configurations {
archives {
extendsFrom configurations.default
}
}
makes Gradle generate the pom with the correct packaging entry, and thus makes it possible to reference the dependency without the #aar suffix

Categories

Resources