Export .clang-format code style to Android Studio - android

Question: Is there a way to import .clang-format code style in Android Studio for native development?
Context:
Hello all,
I am currently working on a cross-platform C++ project, which also involves Android. We have multiple subprojects, including a platform-independent common code base.
The structure of the whole repository looks something like this:
.
├── .idea - Settings for CLion
├── .vscode - Settings for VS Code
├── app
│   ├── android - Full Android project generated by Android Studio
│   │   └── .idea - Settings for Android Studio
│   └── linux - Project for targeting hardware based on Linux
├── core - Platform-independent library with business logic etc.
└── .clang-format - Clang-format configuration file for the whole repository
As you can see, we can use a single .clang-format file for the whole repository regardless of the used IDE (both CLion and VS Code can be configured by this file). However, I couldn't find a way to force Android Studio to also use the style defined there. I should mention that the Android project includes native C++ code, which I want to format using the same code style.
I was thinking about multiple ways to achieve this, but none of them worked. I've tried:
Forcing CLion to use .clang-format and export IDEA XML settings – does not work, as the settings simply include a directive to enable clang-format support
Find a way to convert .clang-format to .editorconfig, which is supported by AS – couldn't find any tools for that, and not sure if the two specs overlap enough.
Look for some plugins, custom on save actions etc. – research in progress, nothing so far.
Does anyone have a working solution or some other ideas I may try?

Try to look into File > Settings > Language & Frameworks > C/C++ you will have ability to change if you want use internal android's studio clang-tidy or external one or clangd.

You can use Android Studio's External Tools to call the clang-format executable directly on the file you want to format.
It's not quite as integrated as the built-in formatter (e.g. "undo" will prompt you to reload from disk), but it gets the job done. After you create the tool, you can run it with CTRL+SHIFT+A then type "clang-format" (or w/e you chose to name it). You can also use Android Studio's Keymap to run the tool.
Either one will format the file currently focused in the editor.
The -style=file argument will tell clang-format to look for your .clang-format file in a parent directory of the file being formatted. The -i flag will tell clang-format to update the file in line (instead of printing to stdout). $FilePath$ is a substitution variable provided by External Tools and will be replaced by the file currently in focus.

Related

Unity Android libs folder

There is a standard way to build Unity applications for Android - to put all jars, manifests and resources in Assets/Plugins/Android forlder.
But we want to componentize or project and to put all staff, related to the certain component, to the folder such as Assets/Packages/Component1/Android
Is there a way to do this with the latest Unity version?
Unity recognizes Plugins folders wherever they are. So, if this is what you want, you can put your stuff into Assets/Packages/Component1/Plugins/Android and put all of those libs there.
Example hierarchy may be.
Assets/Packages/Component1/Scripts - all of the c# scripts here
Assets/Packages/Component1/Plugins/Android - android libs here
Assets/Packages/Component1/Plugins/iOS - ios libs here
etc...

Creating extensions for Adobe air

I'm creating an Java extension for the Adobe AIR android app. I'm very new to Adobe flash. I don't have the flash builder, but only flashdevelop IDE. I follow the instructions from Adobe article to create extensions. The tutorial is very helpful, but unfortunately this is based on Flash Builder.
Step 1 : Create the jar file with the java code -> I did this.
Step 2 : Create an SWC file which is a wrapper to the jar file created in step 1. This is where I'm stuck. I tried to use the ExportSWC4.2 component, but this was not successful. Then now I'm trying to use the compc utility coming with the SDK. In both of these methods, I'm stuck with the problem that I don't know how to include the jar file created in step 1 in the build of the swc using compc. So, I always get the error in my extension as3 file from the wrapper project about the missing java package/extensions.
My current build command is something like :
compc -source-path . -include-classes .... -output ....
So my question is : How can I indicate the compc compiler that it should refer my .jar file?
Or is there a better way to do this?
You don't include a .jar in the build of the swc at all. The swc is only one part of the required components for creating a ANE. Once the swc is created you'll need to extract the library.swf from it. That library.swf needs to be included for each target platform (usually in its own folder) specified by the extension.xml.

PhoneGap 3 and IDEs

I'm trying to grok the best practices workflow for PhoneGap 3, and was wondering how all this is supposed to tie together:
For generic functionality, the code that is developed is in the top-level www folder.
For phone-specific functionality, the code that is developed is under the platforms/platform/ directory.
BUT when using an IDE, the project files seem to be down in the /platforms directory (for example -- the .xcodeproj file for ios is in the /platforms/ios directory), and only includes the files under /platforms, not the top-level www directory.
My question / issue is this. We have a team that's used to working in IDEs like VS / Xcode. How do I set up a project that allows them to work on the top-level www files and emulate on the platform(s) they're focusing on?
The answer to this question appears to have come from the folks over at Adobe.
Brackets is a relatively new open source IDE that is directory structure-focued, along the same vein as Smultron or TextWrangler, for those who are familiar with OS X editors. Hopefully this removes the temptation to go playing around in the /platforms directory instead of editing files in the top-level /www directory.
It has a plugin architecture, with support for Git / GitHub and PhoneGap Build. So far it looks pretty promising.

How to attach javadoc or sources to jars in libs folder?

New version of ADT r17 plugin for Eclipse added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration now. Unfortunately Android Dependencies classpath container is non modifiable.
How can i attach javadoc and sources to the automatically inserted .jar (from /libs folder)?
The best way to answer your question is to summarize the answers from Xavier, plastiv, VinceFR and Christopher.
Step by step guide
In order to link the sources and javadoc to a .jar library that is automatically linked by Eclipse you have to do the following:
Place the library .jar file in the libs folder, and the associated source .jar and doc .jar files in separate subfolders such as libs/src and libs/docs. You can use a name other than src and docs if you want, but it's important that the .jar files aren't directly in the libs folder.
Create a .properties file in the libs folder with the exact name of the actual library .jar (see example). Make sure you keep the .jar part.
Specify the relative paths to the sources and javadoc .jar in the .properties file.
Close and re-open the Eclipse project! Optionally, refresh the project by pressing F5.
Select an object of the linked library in the source code.
Open the Javadoc view in Eclipse to check the documentation (see screenshot).
Open the source code declaration (default shortcut: F3) of the selected object.
Example
The example uses the Gson library.
Directory structure of the libs folder:
libs
├── docs
│   └── gson-2.2.2-javadoc.jar
├── gson-2.2.2.jar
├── gson-2.2.2.jar.properties
└── src
└── gson-2.2.2-sources.jar
Contents of gson-2.2.2.jar.properties
src=src/gson-2.2.2-sources.jar
doc=docs/gson-2.2.2-javadoc.jar
Additional information
You can of course move the javadoc and sources .jar into other folders and specify relative paths. That's up to you. Placing the source and javadoc jars directly into the lib folder is possible but not recommended, as that causes documentation and source code to be included in your application.
Screenshot of the Eclipse JavaDoc panel:
Screenshot of an Eclipse project using Gson with Android 4.2.2.:
Referencing unpacked javadocs
In case you want to reference javadocs which are not provided as a packed .jar but simply as files and folders as asked by android developer in the comments do the following:
Place the library .jar in the libs/ folder
Create a yourlibraryname.jar.properties file (don't forget the .jar) with the following content:
doc=docs
Add the javadocs folders to the libs/ folder.
You should come up with the following folder structure:
├── docs
│   ├── allclasses-frame.html
│   ├── allclasses-noframe.html
│   ├── com
│   │   └── google
│   │   └── ads
│   │   ├── Ad.html
│   │   │  ....
│   │   └── package-tree.html
│   │   ...
│   └── stylesheet.css
├── GoogleAdMobAdsSdk-6.4.1.jar
└── GoogleAdMobAdsSdk-6.4.1.jar.properties
Do not forget to close and re-open the Eclipse project as mentioned above!
Here is a screenshot of a working example project referencing the GoogleAdMobAds Android library.
On windows you have to escape the backslash for references to doc and src paths in the properties file. Example, for
android-support-v4.jar the properties file content is something like:
doc=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\docs
src=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\src
An answer come from http://code.google.com/p/android/issues/detail?id=27490#c21
In your libs folder, you must have:
doc(folder)
foo_doc(folder)
index.html
...
...
foo.jar
foo.jar.properties
And in your foo.jar.properties, just put doc=./doc/foo_doc
Maybe you will have to refresh your project, to clean it, to close it and to reopen it.
It works for me!
I tried all of the above and none of them worked for me. I figured out a method that will always work. Basically, the culprit is the way that the ADT treats the "libs" folder so I quit using the "libs" folder. Instead I created a "libraries" folder and used it.
You can do the following and it will always work - even if the ADT should change how it changes how it deals with the "libs" folder in the future:
Create a "libraries" folder.
Create a sub-folder under it for each library.
Put all of the files for each library in the appropriate folder (java jar file, source jar file, javadoc jar file, etc).
Add the java jar file for each project in the "Libraries" tab for the Java Build Path by clicking on the Add Jars... button to add the jar from the library sub-folder in the "libraries" folder.
Attach the source/javadocs to each project by opening the project in the "Libraries" tab, selecting the desired item, and clicking on the Edit... button to add the source/javadocs from the library sub-folder in the "libraries" folder.
Check the checkbox for each project in the "Order and Export" tab for the Java Build Path.
After verifying that all libraries have been moved delete the "libs" folder.
By following the above procedure your project will have folders that look like this:
Your Java Build Path will look something like this:
In Order and Export the libraries are ticked:
For now, move the library you want Javadoc to lib. Them add that library to the Build Path and add the Javadoc.
Check this comment in the android issues.
On ADT 22 I could not access Javadoc for both commons-io-2.4.jar and android-support-v4.jar
This is the way I fixed it:
Precondition: both libraries are listed under "Referenced Libraries".
Right click on commons-io-2.4.jar and select Properties. This window appears:
commons-io-2.4.jar is bundled with commons-io-2.4-javadoc.jar, so I specified the Javadoc in archive External file path.
I did the same thing for the support library: right click on android-support-v4.jar and select Properties. This screen appears:
This time I specied the path to the source directory.
The library reference to commons-io-2.0.1.jar was broken when I upgraded to SDK Tools and ADT revision 17.
To resolve the problem I used Project -> Properties - > Java Build Path and I selected the Libraries tab. I deleted any reference to commons-io-2.0.1.jar and then used Add Jar to re-add commons-io-2.0.1.jar to the project. Then I click the ‘>’ arrow next to the library name to expand the library reference and I used the edit buttons to set the Source attachment and the Javadoc location.
Sorry I can't post an image as I don't have enough rep (please...).
Seems to be a moving target but, after having collected bits and pieces from many places (including answers to this very question that helped but failed to describe all necessary details, or maybe the system had changed slightly in the meantime), this seems to be the solution, at least as of now (August 28, 2013).
Open up a folder for your javadocs somewhere not inside your project.
Put your javadocs there unzipped, each into its own folder.
Inside your lib folder, add an xxx.jar.properties file for each lib you want to associate a javadoc with.
In that properties file, refer to the folder you unzipped the appropriate javadoc into (on Windows, escape the backslashes):
doc=d:\\Android\\javadoc\\libGoogleAnalyticsServices
Close and reopen your project in Eclipse (refreshing is not enough). You should now see the tooltips when you hover over the appropriate classes.
Failing to observe any of these steps (not unzipping the javadoc, referencing a file instead of a folder, etc) seems to break it.
I know this question is rather old, but when I was facing the same problem yesterday and the solution posted above was way too annoying for me, I found out that one can easily add a source path definition to the .classpath file of the project. Eclipse will then adapt it and you're able to browse through the source.
classpath entry before:
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]"/>
After adding the path to the source
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]" sourcepath="[PATH_TO_MY_SOURCE_JAR]"/>
Hope this helps
just update the ADT plugin. That worked for me!!
Start Eclipse, then select Help > Install New Software.
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:
https://dl-ssl.google.com/android/eclipse/
Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.
Click OK.
In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.
If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
When the installation completes, restart Eclipse
Hope that helps!
For any given jar, if you would like to see the Javadoc help on the tooltip while coding, do the following:
Right click your project > Properties > Java Build Path > Libraries Tab. Click the arrow next to your jar to expand.
Source attachment should point to the location of the actual jar (probably right in your java folder).
Javadoc location: You have two choices here: URL and archive. If your javadocs for this jar are in the form of a folder containing an index.html file at the first level, choose 'Javadoc URL' and point to that folder.
If your javadocs are in a jar, choose 'Javadoc in archive' and point to the jar.
Don't forget to restart your workspace/close and reopen your project to update the tooltip with the Javadoc info.
I hope this helps give a simple answer for what I believe should be a very simple task.
My solution:
Download an eclipse plugin called: "Java Source Attacher Feature".
Later, select a jar and attach the source code using this plugin. Click in the jar file to select it, right buttom on the mouse, and then select "attach java source".
When you have the source code you have automatically the javadoc.
Now you can use F2 over the classes to view the asociated javadoc.
Enjoy

Is there any way to make ADT project directory layout more flexible?

I asked this question on the android-developers group but didn't get any response, so I thought I'd try here.
The ADT eclipse plugin seems to have a pretty rigid idea of how an Android project should be structured - per http://developer.android.com/guide/developing/eclipse-adt.html, it needs to have the AndroidManifest.xml file at the root level of the project, plus res, assets, gen and src folders at the top level, and so on.
I'm wondering if it's possible to get the plugin to be a little more flexible with the layout it recognizes. In particular, I've been using a build plugin for the (scala-based) simple-build-tool, which expects projects to be laid out in a more Maven-like fashion, like so:
src/
main/
AndroidManifest.xml
assets/
res/
scala/
java/
test/
resources
<files to include in test jar here>
scala/
<test Scala sources>
java/
<test Java sources>
(see the simple-build-tool docs).
This is a layout I'm used to from maven-based java development. When I load a project like it up in ADT, though, I get a lot of complaints about a missing AndroidManifest.xml, a missing res directory, and so on. These things are all present, they just aren't where ADT expects them to be.
I don't necessarily need to use ADT to build my project, but I'd like to use it (and Eclipse) for editing. Can anybody tell me whether it's possible to make it more flexible in the directories it uses to find various Android-related resources?
Also, can anyone tell me whether the ADT plugin is open-source? I can't seem to find a link to its source code anywhere.
(As a note, I've also been trying to wrangle sbt to just do things in a way that ADT likes, and it's probably possible to do but it seems very tedious.)
Here's is where you can find the ADT source for r3 0.94, couldn't find the latest though
I do not believe you can change the Android project structure and have ADT understand it. It would be "very tedious" to do that even with the Ant-based command-line builds -- you'd have to make your own copy of the various Android Ant tasks, modify them to suit (and hope the underlying build tools allow what you want), then maintain them forever in the face of Android SDK updates.
Your structure is actually fairly close to the Android expectation, if you consider main/ to be the Android project. If you can convince sbt to allow src/ instead of java/ there, and if sbt won't complain about the resulting bin/ and gen/ you will wind up with in main/ after a compile, you might get it to work.
As far as I can tell, ADT requires those folder names, but there is a workaround: you can create "linked folders" in Eclipse. These are similar to symbolic links in Unix, but are stored in the Eclipse .project file instead of the filesystem, so they are only visible to Eclipse.
You can create one by right clicking in Eclipse the root of the project, and then selecting "Create New Folder". Click on "Advanced" and select the option to create a linked folder. Then type in where you want it to link to. You can use PROJECT_LOC at the begining to specify the project directory, so for your example you would type PROJECT_LOC/src/main/res as the folder to link to, and use the automatically generated name of "res" for the created folder.

Categories

Resources