Android Studio: Change inspection profile for one specific module in project - android-studio

I have several modules in Android Studio project, and I would like to change inspections settings for one of these modules. More precise, I want to turn off all Android-related inspections in one module, but leave all general Java inspections in place.
I need this because I have a not Android-specific Java library module, and that module uses java.util.Properties, and it's load method was implemented in Android API level 9. Since that library is not Andoid stuff, I have not specified Android API level at all, and Studio warns me about that.
It offers adding Android annotation to ignore that inspection, but adding Android dependency to turn off Android warning seems bad.
I can edit the settings to shitch that warning off, but I don't want to turn API level warnings in the whole project.
As I found, in settings you can specify inspection setting either globally or for whole project, not for specific module.
Is there a way to change inspections settings for one module, or do some hack around?
I am using Android Studio 1.3.2.

The Studio should automatically understand that the Java module has nothing with Android, and stopped Android inspections (but they were not disabled, though): I went fix something in the code, rebuilt it several times, and when I returned to warning line, it was clean.
So, I don't actually know what's going on,
but I got some recomendations, that should help:
Sync your Gradle project, it will try to rebuild the project. Some dependencies and settings will only resolve after Gradle will do something internal.
If Gradle will fail, there might be errors in code that ruins interspections. Try to solve them.
If your project history is stored in VCS, try checkout the latest clear version and sync project again.
Check changes in .iml files manually. For some reason, Studio sometimes does weirds edits there, and if I rollback some of them, Studio works better.

Actually you can disable particular inspections being made by Android Studio. However this needs to be on all projects you have in Android Studio, and cannot be done in all modules you are currently developing.
To disable android inspections on your projects follow these steps:
Click on the File menu and Select Settings
Expand the Editor root node select Inspections
There you will have all the inspections which Android Studio checks when building a project (image below). You can expand the Android node and check what you wish to remove from your inspections.
Hope this helps :)

Related

IntelliJ idea does not properly see modules of generated Ktor project. Android Studio does see them

.0. I imported a project to the PC (specifically here = generated Ktor project, although I've seen such behavior before with Compose Desktop projects)
Generated here
.1. IntelliJ Idea doesn't recognize it as a project
When I open the same project on Android Studio = it works fine
Here is how the project supposed to look in IntelliJ (this Ktor project I build manually with IDE and it worked):
.2. I was able to make the project folders visible to IDE:
Repair IDE->Rescan Project Indexes->Reopen Project
Now It look like this:
But IDE still doesn't see my modules properly
How do I properly configure the imported project?
Note: I've read IntelliJ does not show project folders
And tried methods described there. But a lot of answers are hard to replicate as IntelliJ interface changed.
Edit: I've fixed it with Manage Idea Settings->Restore Default Settings. Now projects are opened properly. Thank everyone for your time.
I've fixed the problem with Manage Idea Settings->Restore Default Settings. Now projects are opened properly. Thank everyone for your time.

How to view top-level gradle file in Android Studio?

I my Project tab I'm using the "Android" mode which conveniently groups all Gradle scripts together. I can only see the build.gradle files for the modules though, not the top-level build-gradle. Is there a way to list the top-level build.gradle here as well?
Look for the one labeled Project: [project name without the brackets]:
If you can't see it, it most likely doesn't exist (or Android Studio doesn't see it). Make sure it exists, and if it does, invalidate caches and restart*. If it doesn't, create it.
* A lot of issues related to Android Studio can be fixed this way. If the gradle file exists, but Android Studio isn't seeing it, invalidate the caches and see if that fixes it

Using Android Studio, Adding a Library to build.gradle

I'm using Android Studio, and I'm trying to add the slf4j library using
Build/Edit Libraries and Dependencies.
I clicked on the +, selected Library Dependency, and picked slf4j from the list. Studio added the library to my build.gradle file like this:
dependencies {
compile 'com.android.support:support-v4:24.1.1'
compile 'org.slf4j:slf4j-android:1.7.7'
...
But when I try to run sync, I get this error:
Error:(75, 10) Failed to resolve: org.slf4j:slf4j-android:1.7.7
Is there something else I need to do to my project to be able to use this library??
Turns out what was causing this issue for me (and likely for you, given the build file above) was the Scala plugin. There was a bug with the Scala plugin preventing Android Studio from importing Gradle projects. The fix for this has already been pushed live, so to get Android Studio working again you can either disable the Scala plugin or update it.
Open Settings/Preferences
Open the Plugins section on the left
Find the Scala plugin
Right click on the plugin and click Reload List of Plugins
Right click on the plugin again and click Update Plugin
This allowed me to do a Gradle sync and build from Android Studio again, I hope it helps for you!
It looks like this is a bug with Android Studio. Hopefully it'll be fixed soon.
In the meantime, you can debug your application without launching it from Android Studio by attaching the debugger to a running process of the application. You can do this two ways.
Via the menus: Run -> Attach Debugger to Android Process
Pressing the button that is two to the right of the play/build button. It looks like a grey phone/rectangle with a little green bug in the bottom right
After you do this, a dialog will show up listing available applications to debug. Select your application and press OK. Your breakpoints should now work.
If you need to debug something that happens on app startup, you can tell Android to wait for a debugger when launching certain applications with the following steps:
On the phone open the Android Settings
Open the Developer Options
Make sure Wait for debugger is checked
Press Select debug app and choose your application
Then when you start your application, it'll wait for you to attach a debugger via one of the two methods mentioned above.
Hope this helps!
In order to get the maven repository working with my Android Studio project (which I didn't know is what I was trying to do), I needed to add the following to build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
Apparently, that allows the software to work out the compile commands.

Better to convert IntelliJ project to Gradle or to use Android Studio import project?

If you open an IntelliJ project in Android Studio, there is a warning that you should migrate to Gradle and it sends you to this link. This process seems a bit strange and complicating since the process is not well explained (it's more for experienced programmers who know how Gradle project looks like).
There is also a feature in Android Studio to import IntelliJ IDEA project. I did it with my project and it imported everything (except empty Proguard file), compiled well and all seems to work fine.
However, is this a valid process too - can I safely import future IDEA's project using import feature rather than the solution suggested by Android Studio?
Are there hidden dangers using this method? The least I would like it to continue coding newly imported Gradle-based project and at some point realize that the project is corrupted.
It should be fine. The projects it imports have their Gradle files properly set up, and if it works okay after import, there's nothing about the process by which it created that should make it stop working in the future. I think the link in that warning is just out of date.

How to know whether an existing project was made using android studio or eclipse?

I have got some open source projects which I want to have a try. But I want to use Eclipse if the project was made using eclipse; otherwise I would like to use Android Studio.
So how can I know by viewing the source code about the IDE used for the development of a particular project? Is there any metadata in any file which stores the IDE information?
I believe that Android Studio sometimes includes gradle related files. That's how I would check.

Resources