Run Robolectric in IDEA behind the proxy - android

I have corporate environment with all http and https calls are behind the proxy.
I was able to fix some issues with command line downloads by putting exporting http_proxy environment variable into .profile file.
But with Robolectric 2.2 which is downloading android sources or classes before first run I failed. I don't have CI setup yet so I'm just trying to run tests from idea.
Does anyone know hot to fix it?
I've tried to provide proxy in IDEA settings, I've tried to provide additional environment variable in run configuration. Nothing helps
UPD When I specify proxy in Mac settings it is producing another error:
Unable to find resource 'org.sonatype.oss:oss-parent:pom:7' in repository sonatype (https://oss.sonatype.org/content/groups/public/)
It looks like I'm probably using or missing wrong transitive dependency for Robolectirc (I don't use maven or ivy, I've just downloaded jars from maven central)
UPD2 Nope, It is just timeout again: Error transferring file: Operation timed out

I know that this is a little bit old Question but if you want to use proxy you should put the following file in your home/.m2 directory:
settings.xml
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>your_host_here</host>
<port>your_port_here</port>
</proxy>
</proxies>
</settings>
For gradle look here https://docs.gradle.org/current/userguide/build_environment.html

To add another late answer to an old question :) Since Robolectric 2.4 two properties were introduced to help in the scenario when your Robolectric tests in CI run behind a proxy server:
You have to specify robolectric.offline and robolectric.dependency.dir in your build.gradle file. Something like this:
afterEvaluate {
project.tasks.withType(Test) {
systemProperties.put('robolectric.offline', 'true')
systemProperties.put('robolectric.dependency.dir', "${project.rootDir}/.robolectric/")
}
}
Then you need to download the necessary jars from maven or sonatype and place it in the directory you specified...
I wrote a blog post with more details.

In case this helps someone. Setting the proxy in settings.xml (I tried both possible paths for this file) did not work for me. I ended up passing that as a gradle arguments:
gradle cleanTest test -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>

Related

Flutter submodule in Android project - packages not resolved

I am trying to add a Flutter module to my Android project.
For that, I follow the relevant flutter docs, and everything seemingly works fine.
However, when I run a Gradle sync after following all the steps in above link, the sync returns the following warnings
Failed to resolve: io.flutter:flutter_embedding_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:armeabi_v7a_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:arm64_v8a_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:x86_64_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:x86_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
It seems it cannot find some needed packages in any of the repositories I have specified.
And indeed, I cannot use
import io.flutter.embedding.android.FlutterFragment;
from my Android Java code.
What repository do I have to specify to make sure the needed packages are found?
Solution
I looked through a bunch of questions here on StackOverflow, but nothing seems to really match the problem I ran into.
The closest would be this question, but its answer did not quite work in my case.
Instead I stumbled upon this blog post, where it is recommended to add the following repository:
repositories {
...
maven { url "https://storage.googleapis.com/download.flutter.io" }
}
In my case, I added the repository to settings.gradle in the host Android project (not in the one generated by Flutter). Where you add the repository may vary in your case, and I am not 100% confident that this is the best place.
However, this indeed fixes the problem for me. The packages are found, and I can use the Flutter module as expected.
Details
The repository mentioned in the SO question I mentioned above is accessed via http which may be an issue for some.
Accessing it with https give the following in Firefox:
Websites prove their identity via certificates.
Firefox does not trust this site because it uses a certificate that is not valid for download.flutter.io.
The certificate is only valid for the following names:
*.storage.googleapis.com, *.googleapis.com, commondatastorage.googleapis.com,
*.commondatastorage.googleapis.com, storage.googleapis.com, storage.mtls.googleapis.com,
*.appspot.com.storage.googleapis.com, *.content-storage.googleapis.com,
*.content-storage-p2.googleapis.com, *.content-storage-upload.googleapis.com,
*.content-storage-download.googleapis.com, *.storage-upload.googleapis.com,
*.storage-download.googleapis.com
This indicates to me that https://storage.googleapis.com/download.flutter.io is the correct URL to use for the Maven repository.

How to find which files are using a particular external library in an Android Studio project

The problem
Under "External Libraries" in the project view of an Android Studio project I have these libraries "stax-stax-api:1.0.1#jar" and "xpp3:xpp3:1.1.3.3#jar". They're causing me problems such that I can't build the project. I can't seem to figure out how they got there or where they're being used.
The error message I get when I build right now is:
"Error:Error: xpp3 defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]"
The error message is good except that it doesn't tell me who's using this lib in the first place.
The question
Is there an easy way to find out where they're being used in the project? Or even a way that it's easy but doesn't require looking at every file? It's a multi module project with lots of files. If I could delete them this would tell me but there's no delete option.
This could be something really simple that I'm overlooking. Any help appreciated. Happy to add more info as requested.
What I've tried
I've tried to "Analyze Dependencies" but it doesn't show me any references that I can see.
Update: I forgot to mention that I've also tried ./gradlew app:dependencies but it only tells me that my project depends on these libraries. I already know this. Is there a way to get some more specific information so I can remove the libraries?
Update 2: The accepted answer does work but I needed to redirect console output.
gradle app:dependencies
It will show you the dependencies tree of your project
At this link it is explained quite well about the command and how to use it.
Use this to redirect console output if it's clipped:
./gradlew app:dependencies > dependencies.txt
Project can be explored in "Project-tool-window" to have a look at the used external libraries which are not visible in "Android tool Window".
https://www.jetbrains.com/help/idea/project-tool-window.html
That way I solve my problem. Hope it help.

Gradle Received status code 403 from server: Forbidden

I can't build my android project due to this error. Gradle failed to GET https://www.jitpack.io/com/github/Raizlabs/DBFlow/dbflow/3.1.1/dbflow-3.1.1.pom . Strange enough I am able to view the pom file behind this URL in my browser. What might be the problem here?
My gradle.properties look like this:
systemProp.http.proxyHost=myproxy.local
systemProp.http.proxyPort=3210
systemProp.https.proxyHost=myproxy.local
systemProp.https.proxyPort=3210
systemProp.http.proxyUser=usr
systemProp.http.proxyPassword=pwd
When I remove the proxyUser/Password I get an 407 Proxy Authentication Required.
For me this worked
1. Invalidate caches/restart
2. Sync project with gradle files
Check the local 'gradle.properties'. My problem was on there. Somehow there was some proxy informations and they was wrong. I deleted it and problem solved.
Your proxy needs authentication and the authentication you supply is invalid or your proxy does not allow to request that URL with the authentication details you supply.
You've only provided user/password for systemProp.http. You likely need to provide the same for systemProp.https
See accessing the web via proxy
You need to reset android studio because we cannot get the sever response due to proxy matters.
Close Android Studio.
Please Go to C://Users/Username/.
Then delete .gradle file and .Android Studio File.
After Open Android Studio and set settings.
I solved this problem using above steps.
check gradle offline mode under settings and check local gradle then specify the path of you gradle.zip file its under
Upgrading to Android X can fix the Forbidden! response problem.
Open your project on Android Studio
Top menu > Refactor > Migrate to AndroidX
Don't forget backup your entire project before migrating.
Late answer, but useful, i suppose. I realised that it is not allowed to read jitpack artifacts from a private repository without having a paid subscription:
https://jitpack.io/private
So that's might be a cause for 403 error.
You have an option either upgrade or make the repository public
Subscription must be bought for the repository's owner account.

Running a Robolectric test from IntelliJ causes OutOfMemory

I am trying to run a unit test from IntelliJ that uses Robolectric by following the example here ::
http://pivotal.github.com/robolectric/intellij-quick-start.html
Have added the Robolectric jar and a jar for Junit4. When the test runs I see the following output >>
Have googled around and found some suggestions that I need to specify some vm args. This post is describing a similar issue with Eclipse java heap space The post is concerned with using Robolectric in tandem with a Maven project. I have read that it is easier to use Robolectric inside a Maven project but I have elected not to do this as my Android project has no other use for Maven.
If anyone has any wisdom on what is wrong here it would be greatly appreciated.
Maybe it will help. You need proper local.properties file with android sdk location in the root of your project to run Robolectric correctly:
sdk-location=c:\\Development\\android-sdk-windows
sdk.dir=c:\\Development\\android-sdk-windows
I ran into the same issue and found an answer here: https://coderwall.com/p/rcgyfq
1.- Copy the file "/Applications/IntelliJ IDEA.app/bin/idea.vmoptions" to "~/Library/Preferences/IntelliJIdea12/idea.vmoptions"
2.- Edit file "~/Library/Preferences/IntelliJIdea12/idea.vmoptions"
3.- For example change -Xmx800m by -Xmx2048m
4.- Restart IntellijIDEA 12
This stopped my Out of Memory exceptions and greatly decreased my overall test time.

Android Annotations: Annotated class Xyz_ not finding it's original ("cannot find symbol class Xyz")

I use the latest Android Annotations 2.6 and IntelliJ IDEA.
Sometimes I always keep having problem with the annotations / classpath / compilation order. Seems to occur irregularly. I had the project compile earlier today, then changed a res/layout-xml file later on, then I try to build the project and get an error.
But there are no syntax errors or anything in the xml nor java source files.
Problem is that the annotated class doesn't find it's original class, getting
cannot find symbol class Intro
error.
My project structure:
/src/
/app/activity/Intro
...
/gen-annotation-processed/
/app/activity/Intro_
...
/gen
...
My IDEA annotation preferences:
Processor path:
/path/to/project/ext-libs/androidannotations-2.6.jar
Processor FQ Name:
com.googlecode.androidannotations.AndroidAnnotationProcessor
Source folders in the project's Android IDEA module:
gen
gen-annotation-processed
src
Error login in IDEA when building the project (via IDEA, no ant or maven):
(Class "Intro" exists in the src folder and has no errors in it.)
Update: I have it working now, although not sure what/where I changed something after playing around with settings back and forth. It might actually just be an issue with IDEA and not actually android-annotations related, not sure yet.
What usually seems to work is: do a Rebuild (might throw compile errors, ignore). Then do a Build (not a complete rebuild). For some reasons, the multiple compilation runs don't work properly when doing a rebuild, need to do the rebuild+build combination.
Above mentioned problem was an issue with the new build system that was introduced with IDEA 12, in combination with an issue of AA 2.x, which is meanwhile fixed in AA 3.
See:
http://github.com/excilys/androidannotations/issues/423
http://github.com/excilys/androidannotations/issues/471
(Anyhow, as #outlying mentioned, maven is a good idea in general to make it independent of the IDE at all.)
Have you tried this link http://www.ashokgelal.com/2012/12/setting-up-intellij-idea-12-with-maven-actionbarsherlock-roboelectric-androidannotations/ ?
It works like a charm for me, I was able to setup few projects with AA on IDEA
You have to enable android annotation processing on File->Other Settings->Default Settings..
goto of your app build.gradle
and remove
apt "org.androidannotations:androidannotations:{xxx}"
compile 'org.androidannotations:androidannotations-api:{xxx}'
then put it again
apt "org.androidannotations:androidannotations:{xxx}"
compile 'org.androidannotations:androidannotations-api:{xxx}'
and rebuild
it worked for me

Categories

Resources