I have and Android Studio project I haven't opened in months, and when I look at some individual files there's warning and errors that appear (missing permissions, deprecated functions, etc.).
I want to see all these errors/warnings at once instead of having the navigate to each file to see if it contains any.
When I run Code > Inspect Code with an inspection scope of Whole project, all it returns are warnings about typos and unknown XML attributes:
However, when I run an inspection with a scope of an individual file, it returns errors that aren't in the whole project scope:
The Inspection Profile is the same same in each case: Project Default.
Am I doing something wrong, and is there a way to see all warnings/errors for the entire project?
Run code inspection on an entire project in Android Studio
Step 1:
Got to File>Settings>Plugins
Step 2:
Search for Plugin SonarLint and install it.
Step 3:
Right Click on your project directory and analyze it with sonarLint. You will get all the warnings, errors and code improvements.
Thank you.
Related
I have been following the instructions for integrating the facebook SDK into my apps. I have succeeded in getting all the given sample apps to compile and run except for "helloFacebookSample". For this I get a compilation error:
Project 'HelloFacebookSample' is missing required Java project 'facebook'
My understanding of projects/libraries/build paths etc is a little hazy, but I can not work out why this should fail where all the others succeeded.
Here's a screen grab of my properties window for HelloFacebookSample:
I can confirm that the directory:
c:\android stuff\facebook\facebook-android-sdk-3.0\facebook\bin
contains a file facebooksdk.jar
Any ideas?
EDIT: Thrashing around some more, I just clicked on the "projects" tab that you see in the screen grab above, and saw that it says "facebook (missing)". I'm a bit confused because I thought that projects may need to rely on libraries rather than other projects... but still I have no idea how to resolve the problem. I don't seem to have a project called simply "facebook"...
Edit: thrashing around some more, I just experimentally deleted the "facebook (missing)" from the java build path and then did an "add" of "FacebookSDK"... I thought this was cluttching at straws, but to my surprise it worked!!! HelloFacebookSample compiled and ran!!! - I have no idea what's going on though and would still like an explanation.
The previous version of the Android Facebook SDK referred to the project as 'facebook'. It looks like this sample was not updated to delete the old reference, and add the new one to 'FacebookSDK'. You took the corrective steps to resolve this yourself already by modifying the Java Build Path of the project.
The problem will easily be removed by simply going to the properties of your project and right clicking it, then go to project tab, select the project which prompts missing and remove it.
Now click on project->build project->clean
Now run your project and it will surely do fine
I am using Eclipse Indigo with an Android/NDK mixed project. I've added C++ nature and almost everything is working. Automatic builds work; that is, when I edit a file ndk-build is invoked and completes successfully - no build errors. Mouseover code assist works (the little window pops up with information about the function). If I place the cursor on an include line and press F3, a relevant header file open (not the one I would expect based on my configuration, but a relevant one - maybe a clue?).
If I select the following line in my .cpp file, it opens $NDKROOT/platform/android-3/arch-arm/usr/include/ctype.h:
#include <ctype.h>
(isdigit is defined in this file)
However, Eclipse insists that isdigit is not defined. I have read many posts suggesting that either the static analyzer or the indexer is to blame, but I've tried many of the suggested solutions to no avail.
If I add a line like the following, the error goes away and mouseover code assist for the function works:
extern int isdigit(int);
Again, this is not a linker error or a compiler error - ndk-build completes with no errors. This is something inside eclipse. Thanks for taking a look!
Edit: I now believe this to be a Code Analysis problem. A better solution is to edit the Code Analysis options to make "Function could not be resolved" be a warning instead of an error. That way you can see the warnings in Problems view, but continue to work. If the function is REALLY missing, the compiler will tell you! I also have a new theory, that the problem is with the Code Analyzer following symlinks, because all of the "missing" functions are in symlinked include files. Would love any input on this theory.
After spending several days working on problems like this, I developed the following recipe for dealing with issue.
I hope it helps you or others:
Summary: Usually, your problems in eclipse are due to eclipse configuration problems. The following assumes that your C++ code is building ok with ndk_build or ndk_build.cmd (on windows).
No joy with eclipse juno (4.2) and CDT version 8.1. Use eclipse indigo (3.7)
Make sure that you have the CDT for indigo installed and enabled (version 8.0X) by looking in the "install new software". It defaults to installed but not enabled on indigo on some downloads.
When you are dealing with native code or android config for native code, make sure you are in the C++/C perspective in eclipse, not the java one. It is deceptive, but there is a only a subset of options available in Java perspective. You can be sure you are C++/C perspective if you see "C/C++ general" as a choice when you do "Project > Properties."
The usual problem is that the indexer in C/C++-land thinks there are errors when there is not (e.g. building with ndk-build works ok, often you can see this in the console window even). This is caused by bad paths in the "Paths And Symbols" part of "Project > Properties > C/C++ General" on the first tab.
To fix the problem, the primary tool is to right-click on the project, select "Index" and "Search for unresolved includes." This will tell what files it can't find--and these are typically not the ones that you have in your files with the little pink mark by them.
To find the right file, search in your NDKROOT directory (where you installed NDK). A typical one to add is: ${NDKROOT}/platforms/android-9/arch-arm/usr/include or the right android-N for your android target. There are many copies of the standard include directories in the NDK because of multiple versions of android and copies of the C++ standard libraries.
Two big warnings
The "unresolved includes" view in eclipse does not automatically update when you change the indexer configuration on the Properties > C/C++ General/Paths and Settings so be sure to run it again each time. Most views in eclipse do this update properly!
Also the little red/pink error markers in the source code views in the eclipse editor don't automatically update either. You have to "touch" the file in some way for it discover that the error is now fixed.
I worked around this issue via the approach I suggested in my question and haven't been able to find a better way yet.
Perhaps this will help:
Go to Project > Properties
Navigate to C/C++ Build > Settings
Go to GCC C Linker > Miscellaneous settings
Add the following in the Linker flags : -lc
Have you tried rebuilding the indexer? (right click project in project explorer index->rebuild)
Sometimes that takes care of problem... If you upgraded from an earlier version of eclipse your indexer setup could be a problem -- you might want to try restoring the indexer defaults (preferences c/c++ Indexer)... Hope this helps – this issue can be 'maddening' (seems to happen way to often)
I had the same problem on Linux with different toolchains. Even the simplest C++ code (like the one create by the hello wizards) would have syntax errors, without aby build problem. As pointed out in another post by Thorbjorn Jemander the problem is in the indexer and it can be eliminated by deselecting the option "Allow heuristic resulution of includes". Explicitely: Winsow -> Preferences -> C/C++ -> Indexer -> deselect the above option.
After that you may see that highlighted errors disappear after you open the file in editor and just click within the editor page...
I have several Android projects in an Eclipse workspace:
a stand-alone application project with a class my.package.Foo
a library project with a different class my.package.Foo
two application projects that depend on the library project and contain no source code
The problem comes when working with one of the applications built on top of the library project. When it crashes (sadly, a frequent occurrence), I double-click on a line of the stack trace in the logcat to go to the relevant source. The problem is, if the line is for Foo.java, Eclipse always opens the source from the stand-alone project. The only way I can direct Eclipse to the right source is to close the stand-alone project, which is somewhat inconvenient.
Is there any way to get Eclipse to pay attention to which application actually crashed when it looks for the relevant source file? I assume that this is some sort of classpath problem (similar to that described in this post). However, I don't see anything in the Android run configuration properties for modifying the class path. Eclipse always seems to run through the workspace projects in alphabetical order by name and opens the first my/package/Foo.java it finds.
I'm using the latest Android ADT and SDK versions.
Per the link provided in the comment by #blessenm, this is an issue with logcat in Eclipse. We should see a fix in Release 20 of the SDK tools. As can be seen here, the patch that fixes it has been completed and is in line for final approval.
Meanwhile, the best thing to do is to change the logcat preferences (Window -> Preferences -> Android -> LogCat) so that the double-click action is "Go to Problem (method declaration)" instead of the default "Go to Problem (error line)". This isn't foolproof: it will at least open the file but if there are multiple methods with the same name, it will go to the first method, regardless of signature. (When the fix is incorporated, there will be no need for options for double-click action and it should disappear from the preferences.)
Everything was working fine yesterday. I start to work on my project today and Eclipse gives me a bunch of problems. First, it wouldn't let me debug saying "Cannot connect to vm". I don't exactly remember how I fixed that problem, but I did. I was able to debug once again. I just recently created a new project to test something separate from my main project and now Eclipse is giving me some more problems. This time it is saying "An internal error occurred during: "Launching New_configuration".
Path for project must have only one segment."
After some searching, I found that it is related to the debug configurations. In order to debug a project now I have to go to Run->Run Configurations and select the project I want to debug. Before, it would automatically do this for me. I would just select a java file from a project and it would debug the project that contained the file. Also, I can't find my new project in the list of Android Applications under Run->Run Configurations. I've tried creating a new one in the menu, but when specifying a source it can't find my project folder even though it is clearly open in Eclipse. Eclipse has been giving me massive headaches lately and I don't understand what could have caused this to happen. Eclipse was left open all night and the computer doesn't go into sleep mode (sorry for wasting power!).
Any ideas on how to get it to see my project and make it automatically debug the right project?
What is the usual case (detailed below as a Run or Debug configuration with no project name) wasn't the root cause:
In the comments, I suggested:
Did you try to import this existing project in a brand new workspace? (to see if this isn't related to some kind of workspace metadata corruption?)
To which the OP Atlos replied:
creating a new workspace seemed to have fixed it. Not sure what could have happened to my old workspace to cause a problem like this.
Should I ditch my old workspace and just import stuff into the new one?
It happens, and can be caused by some process blocking the update of metadata, rendering parts of the workspace unsound.
It is perfectly OK in that case to save/move that old workspace (for reference just in case) and to create a brand new one.
This blog post mentions:
It seems that this rather cryptic message means nothing more in my case than “please enter a name and project for your run configuration”.
I did have a “name”, but left the “Project” field empty. Entering a value in the ‘project’ (the “AndroBlip” you see next to ‘browse’) fixed it.
Sources seem to indicate that the same error is produced if you don’t enter a value in the ‘name’-field.
It actually references the similar SO question "Android: “Path for project must have only one segment”".
Note that you would see the same error for trying to have a project within another project (as detailed in this thread).
Basically, I need help importing downloaded source or creating a project from sample source programs. I'm looking for step by step instructions for both if anyone can point me there or post the steps.
I'm very new to Android/Eclipse. I have the environments installed and have successfully written a very minor app that works on the emulator and my real Droid X. I cannot, however, get any of the Android samples into a project without errors. I've tried importing, creating from existing source, and etcetera and it's all a mess with errors everywhere.
I have, however, successfully created a new empty project, then brought the components into the project one at a time typing or pasting in code for every file. I'd hover over and import Android and other components as needed. The WiktionarySimple, for example, ran with only a couple of changes and several warnings that I left alone. (I had to add 'formatted="false" in the statements below...)
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title" formatted="false">"Wiktionary:Word of the day/%s %s"</string>
But there has to be an easier way to import! I've done the intuitive and I've followed instructions that I've found, but to no avail. Can anyone give me a complete list as to how to import or create a project from existing source or from source I've downloaded from the web?
Step #1: Start a new Android project
Step #2: In the first page of the Android project wizard, choose the "Create project from existing source" radio button, then click the Browse button and find the directory containing the project
Step #3: Tweak settings to suit, then press Finish
Step #4: If needed (not sure if it is anymore), right-click over the project name, and choose Build Path > Configure Build Path from the context menu, and make sure the Android entry in the checklist is checked
Its quite possible that you are not importing these projects incorrectly and that you are simply running into common problems that occur when importing projects.
For instance your problem involving adding formatted="false" is quite common and due to a change in the strictness of aapt, which is explained in this question. It is likely that the sample project was created before the change and has not been updated since.
That error involving the formatted="false" can also cause many more errors, since any xml after that error is often not parsed and thus any resources declared after it are not known. So the error No resource found that matches the given name (at 'hint' with value '#string/search_hint') and others like it are often due to the formatted="false" error. I would suggest fixing all the % sign errors with the formatted="false" then letting it rebuild and see how many errors are left.
As for the String types not allowed (at 'layout_width' with value 'match_parent') a quick search on stackoverflow says that its caused because FILL_PARENT was replaced with MATCH_PARENT in Android 2.2. So you need to set your sdk for the project to be Android 2.2 or higher. Here is the link to that question as well.
This happened to me in importing the wiktionary sample and i found the solution.
Import the project through existing code
Right click project and choose properties
In 'Android' Tab the default choice is the minimum API. Changed it to the latest(highest API)
Click ok.
Clean and build your project and errors will be gone
(probably optional)
6. Change the target and Minimum SDK in the Android Manifest