Android Studio: How to attach javadoc - intellij-idea

It might be very trivial question, But I couldn't find any option to attach javadoc/source with local jar dependencies (in libs folder) in android project. I can't believe I have spent a hour on such simple stuff :(
Google search result just tells about adding android documentation or adding javadoc in eclipse. That's not What I am looking for!

I found a solution just now since I can't find any other solution for a long time.
suppose:
your lib name is: libxxx.jar
javadoc name is docs.zip
under folder .idea/libraries, you can find libxxx.xml. replace JAVADOC with
<JAVADOC>
<root url="jar://C:/yourpath/doc.zip!/" />
</JAVADOC>
then ctrl+alt+y to sync the project. (Don't do "Sync Project with Gradle files", it will delete the changes)

I've found & tested a way in which we can add the javadocs without loosing them after a gradle sync.
Right click in Project panel > External libraries > lib-name
Click Library properties
Click specify documentation URL
And specify an URL. For my machine it was file:///opt/android-sdk/extras/google/google_play_services/docs/reference
The result was:
And after a project sync I could browse the javadoc of the google play services
Note:
This placed the same JAVADOC entry in the xml identified by Jason but doesn't disappear after doing a sync with gradle

It is possible:
Open Project structure
Navigate to dependency that you want
Press button from the screenshot and provide folder or file
Another way to attach sources:
Step into class from library (Hover mouse over class name and do CMD + Left click or CMD + B)
You will see decompiled version of class there menu on the top right side of editor "Attach sources.."

I had problem with answer from Matyas that I wasn't seeing my local .jar library in the External Libraries list, because it only show maven attached libs.
Solution is mentioned here: https://code.google.com/p/android/issues/detail?id=73087#c26
Right click on the "Structure" tab and check "Split Mode" (so you can open both "Project" and "Structure" tabs at same time).
Open both "Project" and "Structure" tabs at the same time.
In "Project" tab select "Android" perspective and then select your module folder (e.g. "app")
In "Structure" window you should now see list of all libraries, including your local *.jar
Continue as in answer from Matyas:
Right click on wanted library and select "Library Properties..."
If you have *.jar with javadocs locally, you can press "add" button (green "+") and search for the file on your disk (you don't have to type "file://" path manually).

Still a current issue as of my posting it seems:
https://code.google.com/p/android/issues/detail?id=73087

After some investigation, I stumbled upon this:
https://github.com/xujiaao/AARLinkSources
Works like magic!

I wasted so much time on this too...
Here's a gradle task which finds source and javadoc by location/naming convention, and registers them in the .idea files on sync. It belongs in the root gradle file's allProjects section. As-is, it expects to find [projectname]/libs/lib.jar next to lib-sources.jar and/or lib-javadoc.jar. Also, as noted in comments, if your javadocs not pathed at "/" inside the jar, you may need to change the script to add "docs/html" (for example) at the end of "jar://$doc!/".
allprojects {
task addJavaDoc {
afterEvaluate {
// Specify paths, this will be run per non-root project
def projectDir = project.getProjectDir().getCanonicalPath()
def rootDir = project.getRootDir().getCanonicalPath()
def lib = projectDir + '/libs'
// println lib // Uncomment this to troubleshoot
// Get any jar dependencies register in the lib folder
fileTree(include: ['*.jar'], exclude: ['*-source.jar', '*-javadoc.jar'], dir: lib ).each { File jar ->
def jarName = jar.getName()
def moduleName = jarName.substring(0, jarName.lastIndexOf("."))
// IntelliJ does this to file names when making the xml files
def escapedName = moduleName.replace("-", "_").replace(".", "_")
def xmlFile = "$rootDir/.idea/libraries/${escapedName}.xml"
// println xmlFile // Uncomment this to troubleshoot
if (new File(xmlFile).exists()) {
['javadoc', 'sources'].each {String docType ->
// Get sources or java doc by naming convention, (expects name-sources or name-javadoc
def doc = "$lib/$moduleName-${docType}.jar"
// println doc // Uncomment this to troubleshoot
if(new File(doc).exists()) {
def xml = new XmlParser().parse(xmlFile);
def xmlTag = docType.toUpperCase()
// Perform xml replacement by convention
xml.library[xmlTag].replaceNode {
"$xmlTag" {
root(url: "jar://$doc!/")
}
}
// Write out changes
new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile))).print(xml)
// Notify that changes worked
println "Fixed up reference to $doc"
}
}
}
}
}
}
}
Also, if you are using jcenter or mavencentral, javadocs and sources should work for downloaded jars without using that task, but you may have to add this in each non-root gradle file:
apply plugin: 'idea'
idea{
module {
downloadJavadoc = true
downloadSources = true
}
}

Personally tested successfully!
1.Project Structure(ctrl+alt+shift+s)
2.SDK Location
3.JDK Location
4.UnCheck "Use embedded JDK(recommended)"
5.Select your own jdk path(My Path:C:\Program Files\Java\jdk1.8.0_111)
6.Synchronized(ctrl+alt+y)
success

in android studio if you use compileSdkVersion 23 in buidl.gradle and you have downloaded the SDK 23 document file and source file in SDK manager , the android API and java API doc and source will all show auto, you don't need to manual set.

There is a solution, This procedure take place through terminal ,
I have tested solution in MAC OS.
1) Move to your project folder
2) ls -al (to show hidden files)
3) Move to .idea folder , Command : cd .idea
4) Move to libraries folder , Command : cd libraries/
5) Now you can see list of all xml files for your libs or jars. Edit it like , vi open androidasync_2_1_7.xml
6) In the editor screen ,
For inserting
Press i
Now you see <SOURCES /> tag we have to provide a path here like,
<SOURCES>
<root url="file://$PROJECT_DIR$/androidasync/src/main/java" />
</SOURCES>
For exiting
Press Esc
:wq //for exiting and saving
:q! //for exiting without saving
7) Restart Android studio (Sometime it needed also sync gradle).

Related

IntelliJ Tomcat Automatic Redeploy when running a gradle task

What I am trying to accomplish:
I want the tomcat 9 server to execute an automatic redeploy when I run a Gradle task that updates my HTML files.
This is my setup:
I use IntelliJ 2020.03 (ultimate edition), tomcat 9, the application is a GWT application.
My Configuration for Tomcat:
This is what I see when I hit the "Configure ..." button next to the line labeled "Application server:"
This is my Gradle task I run but tomcat does not automatically redeploy the changes
Things I already tried:
According to [https://www.jetbrains.com/help/idea/updating-applications-on-application-servers.html] I should have an option to "Update resources". But my options are limited to:
Therefore I assume I need to have "Exploded artifacts in local application server run configurations".
Therefore I headed to Tomcat -> Edit Configuration
I replaced the deploy to the exploded artifact:
Using this I get the following error message on starting up tomcat:
[2021-02-12 08:46:05,533] Artifact Gradle : NewComApp.war (exploded): com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: C:\Users\heckner\IdeaProjects\NewComApp\build\libs\exploded\NewComApp.war not found for the web module.
So I decided to compare the artifact that "works" (but does not update the HTML files) with the "exploded" artifact which would be probably the right one but throws an error message on startup of tomcat.
This is the one which works ("NewComWar.war"):
This is the one which does throw an error message on startup ("NewComApp.war (exploded)":
As you can see in the image under "... which works". the war already seems to be "exploded". So why does IntelliJ does not offer the "update resources"?
But never the less, when I switch in Tomcat Edition to "NewCompApp.war (exploded)" i am able to select "update resources" in the drop down:
So probably this would be the way to go.
It obviously boils down to the point: What is wrong with the artifact declaration above so that tomcat throws the error message?
The feedback was: "ctually "NewComWar.war" is an archive that contains exploded artifact, that's why only "Redeploy" is possible. Please check that exploded artifact is created in "Output directory". "
Now the question is how I can add the exploded war to the Output Directory?
I tried:
but then I can only select from:
When I add this, it looks like this:
When I run Tomcat, it still says:
[2021-02-12 12:24:54,224] Artifact Gradle : NewComApp.war (exploded): com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: C:\Users\heckner\IdeaProjects\NewComApp\build\libs\exploded\NewComApp.war not found for the web module.
Now I found the following tip (thanks Evgeny):
https://youtrack.jetbrains.com/issue/IDEA-178450#focus=streamItem-27-4068591.0-0
I switched under Settings -> Build, Execution, Deployment -> Build Tools -> Gradle: "Build and Run:" IntelliJ IDEA
I added this snipped to build.gradle:
task explodedWar(type: Copy) {
into "$buildDir/libs/exploded/${war.archiveFileName.get()}"
with war
}
war.dependsOn explodedWar
I switched the artifact which is deployed to the tomcat to
this automatically added the Gradle task:
Build 'Gradle:NewComApp.war (exploded) artifact to the
which is defined like this:
This accomplishes two things:
I can choose "Update resources" on my Edit Configuration for Tomcat like shown below:
My deployment runs well under tomcat
But ... :-)
Updates to the HTML files (within the war file) are not exploded to the NewComWar.war directory.
When I start tomcat I see the following file structure under C:\users<myname>\IdeaProjects\NewComApp\Libs\
The reason for this is that we use a Gradle task that generates the HTML files.
This task is called "copyHTML"
Under build.gradle it is defined now as follows:
war {
from 'war'
dependsOn copyHtml
exclude excludeInWar
doFirst {
manifest {
def version = ant.hasProperty('gitversion') ? ant.gitversion : 'undefined version'
println "Version: ${version}"
attributes("Implementation-Title": project.name, "Implementation-Version": version, "Built-By": new Date())
}
}
}
task explodedWar(type: Copy) {
into "$buildDir/libs/exploded/${war.archiveFileName.get()}"
with war
}
war.dependsOn explodedWar
copyHtml {
dependsOn generatorClasses
inputs.dir 'html'
inputs.dir 'email'
inputs.dir 'email.Tags'
inputs.dir props.getProperty('generator.htmlfiles.prefix') + 'html'
inputs.dir props.getProperty('generator.htmlfiles.prefix') + 'html.MeetingApp'
inputs.dir props.getProperty('generator.htmlfiles.prefix') + 'staticHtml'
inputs.properties props
outputs.dirs 'war', 'resources/com/newcomapp/server/mail'
doFirst {
ant.properties["generator.classpath"] = sourceSets.generator.runtimeClasspath.getAsPath()
}
}
task warWithoutGwt(type: War, dependsOn: war) {
}
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(warWithoutGwt)) {
compileGwt.enabled = false
}
}
When I run the Gradle task "warWithoutGWT" while tomcat still runs it says:
C:\Users<myname>\IdeaProjects\NewComApp\build\libs\exploded\NewComApp.war\WEB-INF\classes\com\newcomapp\server\integration\GeoLite2-Country.mmdb (The operation is not applicable to a file with an open area assigned to a user)
I assume that tomcat still holds a reference to that file, and the Gradle task tries to overwrite it (although there was no change to that file). Furthermore, I assume that this kills the rest of the Gradle task so that it does not update the HTML files (it's only an assumption though). How can I arrange an exploded war so that write-protected files are omitted and do not kill the rest of the Gradle task execution?
My answer up to now for this problem is: I changed the gradle script:
task explodedWar(type: Copy) {
into "$buildDir/libs/exploded/${war.archiveFileName.get()}"
exclude "**/*.mmdb"
with war
}
war.dependsOn explodedWar
so I added an "exclude for mmdb files". And this really works.
Is this a correct and good solution or do I overlook something? The reason I am asking is that changing HTML files in the scope of tomcat should be something very common with tomcat based projects. So I wonder if there is a more standardized, easier solution to this? It seems quite clumsy to copy and explode with additional gradle tasks the war file instead of IDEA take care of this.

Disabling Node.js download in KotlinJS Gradle plugin

The version of Node.js that KotlinJS downloads (as of 1.3.40+) seems not to work in Alpine Linux. The docker image I'm using already has Node baked into it, so there's no reason not to use that one.
However, I'm having trouble figuring out how to set download to false (which should cause KotlinJS to build using the node on the PATH).
The relevant section of my build.gradle looks like this:
kotlin {
target {
useCommonJs()
browser()
}
}
Any help would be appreciated!
Looks like it's pretty similar to #talalUcef's answer:
kotlinNodeJs {
download = false
}
Using the KotlinBrowserJs plugin applies the NodeJsRoot plugin.
The NodeJsRoot plugin applies itself, which causes the NodeJsRootExtension to be included under the name kotlinNodeJs.
Thus, I believe, any of the vars here can be set inside a kotlinNodeJs block.
You can add
node {
download = false
}
on your build.gradle file

intellij "object index is not a member of package views.html"

I've got Intellij 15.0.5 and I cannot get rid of this error
object index is not a member of package views.
I've created a new play project in Intellij and also using the activator command
activator new PlayTestProject
But I keep getting the above error. I've read all the other similar question on SO but none of them helped and I've tried the following
Right click the project -> Add framework support -> select "Play 2"
Result: I didn't see any change to my project. When I hit OK, the window disappears but if I try the same the second time. Nothing happens and the window is still there!
Preferences -> Languages & Frameworks -> Play2 -> select "Use Play 2 compiler for this project"
Result: I get this error
Error:Module 'client' production: java.lang.NullPointerException
I've tried
invalidate cache & restart
sbt clean
checkout a fresh new project
But I keep getting the same error in Intellij.
Running sbt compile on command line runs the build successful. But Intellij keeps shows me the above error.
How do I fix this ?
Alright if anyone is running into the same problem. The fix was to mark the following two directories as Sources Roots in Intellij.
/target/twirl/main
/target/routes
Steps:
Right click the target folder -> Mark directory as -> Cancel exclusion (If you don't see Cancel exclusion do the next step.
Right click the target/scala-2.11/twirl/main folder -> Mark directory as -> Sources Root
Right click the target/scala-2.11/routes folder -> Mark directory as -> Sources Root
Right click the project Open module settings -> Sources -> and remove the above two directories if there are added in the Excluded folder's section.
This fixed my problem.
I found this problem and it appeared to be caused by an incomplete compile within sbt. (I had done "sbt clean ; sbt compile" but then aborted the compile with Ctrl+C because it had a error.)
Intellij worked correctly again after I ran:
sbt clean
After removing the .idea/ folder, I could successfully re-open/import my project, and the errors were gone.
Just remove the #() from top of index.scala.html because there are no parameters.
#()
<!DOCTYPE html>
<html lang="en">
And in Action you have
def index = Action {
Ok(views.html.index())
}
I had a similar error and just had to run npm install to fetch the necessary dependencies. Listing it here in case anyone has the same issue.

F4 IDE gives "Invalid Uri scheme for local file" when running Fantom app

I started a very simple project using Xored's F4 IDE for Fantom. The first few times I ran it there was no error, but I started adding dependencies (fanbatis) and at some point the error below starting showing up every time I run a test or a dummy Hello World app.
[23:44:18 22-Nov-13] [err] [pathenv] Cannot parse path: C:\dev\f4workspace\auth\bin\fan
sys::ArgErr: Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
fan.sys.LocalFile.uriToFile (LocalFile.java:64)
fan.sys.File.make (File.java:26)
util::PathEnv.parsePath (PathEnv.fan:47)
fan.sys.List.each (List.java:555)
util::PathEnv.parsePath (PathEnv.fan:43)
util::PathEnv.make$ (PathEnv.fan:22)
util::PathEnv.make (PathEnv.fan:20)
java.lang.reflect.Method.invoke (Unknown)
fan.sys.Method.invoke (Method.java:559)
fan.sys.Method$MethodFunc.callList (Method.java:198)
fan.sys.Type.make (Type.java:246)
fan.sys.ClassType.make (ClassType.java:110)
fan.sys.Type.make (Type.java:236)
fan.sys.Sys.initEnv (Sys.java:447)
fan.sys.Sys. (Sys.java:224)
fanx.tools.Fan.execute (Fan.java:28)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)
Hello, World!
It is more a nuisance at the moment because the tests and the dummy app still run. I created another project, copying all the source code adding class by class and testing after each change and the error never occurred. Any ideas please?
That's an interesting issue!
tl/dr: you have an empty project 'auth' in your workspace, either create some dummy class inside it or go to Run -> Run configurations, find your launch config and uncheck project without sources on 'Projects' tab.
In order to keep your Fantom installation clean from projects in a workspace, F4 puts built pods into project/bin/fan/lib/fan. When F4 launches projects from workspace, it uses PathEnv and builds FAN_ENV_PATH by joining paths to Fantom installation and bin/ folders in projects in workspace.
When Fantom runtime analyzes FAN_ENV_PATH, at first it interprets a path as native OS path, but if dir does not exist, it attempts to interpret it as file URI, here's relevant part of PathEnv source:
path.split(File.pathSep[0]).each |item|
{
if (item.isEmpty) return
dir := File.os(item).normalize
if (!dir.exists) dir = File(item.toUri.plusSlash, false).normalize
if (!dir.exists) { log.warn("Dir not found: $dir"); return }
The problem code is item.toUri – On Mac OS X and Linux this is parsed as an URI without scheme with path only, so if directory does not exist, this code just prints a warning in a console.
But on Windows, because of disk name in path, disk name is interpreted as scheme:
fansh> "C:\\Users".toUri { echo(path); echo(scheme) }
[\Users]
c
fansh> "/Users".toUri { echo(path); echo(scheme) }
[Users]
null
And then File constructor fails, because expects either 'file' scheme, or null scheme:
public static java.io.File uriToFile(Uri uri)
{
if (uri.scheme() != null && !uri.scheme().equals("file"))
throw ArgErr.make("Invalid Uri scheme for local file: " + uri);
return new java.io.File(uriToPath(uri));
}
I've created an issue here, so that F4 would automatically skip empty projects when building FAN_ENV_PATH – https://github.com/xored/f4/issues/25.
I thought the problem had something to do with the forward slash at the end of path as shown in this line of the error message
Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
However, I found that such path didn't exist. I manually created both the bin and the fan folders and the error disappeared. To be honest I don't really know why F4 needs and checks for that folder because so far it hasn't written any file in it.

Sublime Text 2 and ZF2 ... auto complete not works

I installed sublime text 2 with all php dependencies.
And also a package for code complete called sublimecodeintel.
There is not zf2 supported auto code complete.
For example, when I start writing
\Zend\Form\...
at each steps CTRL+Space does not give any subclasses of Form
or for example after this:
$testimonial = new \Application\Entity\Testimonial();
when I write this:
$testimonial->
CTRL+Space shows a list but there is no methods listed from Testimonial php class.
Please help.
You might need to add the path to the ZF2 folder if they aren't in one of the project folders, or you could add a .codeintel/config file to your project root and add:
{
"PHP": {
"php": '/usr/bin/php',
"phpExtraPaths": ['path/to/ZF2'],
"phpConfigFile": 'php.ini'
}
}
So make sure you have the paths set up correctly, and it should work.
Also SublimeCodeIntels default mappings for autocomple is:
Linux: shift+ctrl+space
Mac: shift+super+space
Windows: shift+ctrl+space
Sublime Text 2 is not an IDE and so does not have autocomplete. You could try installing the SublimeCodeIntel package and see if that works for you.
Alternatively, consider NetBeans, PHPStorm, Zend Studio or Eclipse/PDT which are all IDEs that understand how to do auto complete with PHP.