Inferring Nullity runs forever - android

When I select Analyze - Infer nullity... in the android studio menu and select any scope (tried even running on a single file) message pops up and says:
The module ... doesn't refer to the existing 'support-annotations'
library with Android nullity annotations. Would you like to add
dependency now?
I click "OK" and then gradle sync starts and progress bar with "infer nullity annotations" title is shown. Then it runs forever like this
I tried adding manually this in gradle:
compile 'com.android.support:support-annotations:23.4.0'
But still have the same result.

I had the exact same issue, but I managed to solve it by manually adding the newest version of the annotations support library to the project through Android Studio build options (it's found on Build -> Edit Libraries and Dependencies on Mac).
The thing here is that Android Studio will probably give you some kind of a warning if you add a support library whose version number is higher than your target API build, but add it anyway. Not sure why, but that did the trick for me.

Related

What is the correct way to move gradle dependency versions to a variable?

In order to maintain the version numbers of my gradle dependencies, I chose the below pattern.
In my project level build.gradle I added:
ext.versions = [
'kotlin_version' : '1.2.30',
'dagger' : '2.16'
]
And in my app module's build.gradle I added:
implementation "com.google.dagger:dagger:${versions.dagger}"
implementation "com.google.dagger:dagger-android-support:${versions.dagger}"
implementation "com.google.dagger:dagger-android:${versions.dagger}"
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
kapt "com.google.dagger:dagger-android-processor:${versions.dagger}"
But my problem is after doing this, I lost the lint warnings of "Newer Library versions available".
What is the correct way to do this without missing the lint checks?
Note: I have also tried other ways like moving these versions to gradle.properties file (for global variables).
I am looking for a solution inside Android Studio. There is one solution which I already found:
Analyze -> Run Inspection by name... -> Type "Newer Library Versions Available"
But my concern is, it is easy to miss on updates until we run some or the other script. That is why I am trying to find a way where dependency versions can be put in a variable and get lint warning for new updates.
See this answer: https://stackoverflow.com/a/46296198/2053763
There is a link to a gradle plugin which can check for dependency updates.
Android Studio 3.1.2 offers some lint checks while using version variables, but still misses some of the updates. See image below:
You can extract dependencies versions into variables stored in a separate Gradle file and then check and update them from the Project Structure (ctrl+alt+shift+S) (screenshot from Android Studio 3.6.3):

Android studio automatically tries to update libraries?

In my project I have many libraries defined in dependencies section in gradle. Problem is once in a while (once/twice a day)Android Studio gives me errors like this when opening the project or trying to get a release output:
Error:Unable to resolve dependency for ':TMessagesProj#armv7Debug/compileClasspath': Could not resolve com.google.android.gms:play-services-gcm:11.2.+.
My guess is it is because build tools is trying to check if there is an update for each library and when it doesn't find an Internet connection, it shows this error. If so, how can I change the setting in a way it doesn't have to check for updates? In other words in my project I don't need to update my libraries.
I know there is an offline mode that will probably do the trick! But I don't want to use this feature because it will probably disable some other useful features too. I just want to prevent it from automatically checking for library updates(If that's the problem shown above).
I included some part of my dependencies in gradle here:
dependencies {
compile 'com.google.android.gms:play-services-gcm:11.2.+'
compile 'com.google.android.gms:play-services-maps:11.2.+'
compile 'com.google.android.gms:play-services-vision:11.2.+'
compile 'com.google.android.gms:play-services-wallet:11.2.+'
}
Dependencies with a plus like 11.2.+' will always lead to repeated builds.
You have to specify the full version like:
com.google.android.gms:play-services-gcm:11.2.0
If you do not specify gradle will always be building because its looking for the latest version online of 11.2.+ may be 11.2.4, 11.2.6 etc

Issue with DJI SDK gradle 4.4.0, provided keyword in gradle not working

Previously my gradle used to look like this and worked fine (apart from few registered bugs)
implementation 'com.dji:dji-sdk:4.3.2'
Now, after changing to
implementation 'com.dji:dji-sdk:4.4.0'
the Camera and other files cannot be recognized anymore. I am attaching a screenshot of the unrecognized imports.
However when I am trying to add
//dji-drones-sdk
implementation 'com.dji:dji-sdk:4.4.0'
provided 'com.dji:dji-sdk-provided:4.4.0'
I am getting "could not download dji-sdk-provided.jar"
Screenshot attached
All the examples and github codes are in version 4.3.2. Can anyone help me out?
Here is the link to the dji sdk
I have found the issue. After Gradle 3.4, the "provided" is replaced by "compileOnly"
I quote,
Gradle adds the dependency to the compilation classpath only (it is not added to the build output). This is useful when you're creating an Android library module and you need the dependency during compilation, but it's optional to have present at runtime. That is, if you use this configuration, then your library module must include a runtime condition to check whether the dependency is available, and then gracefully change its behavior so it can still function if it's not provided. This helps reduce the size of the final APK by not adding transient dependencies that aren't critical. This configuration behaves just like provided (which is now deprecated).
Hence using compileOnly in place of provided will do the trick.
Here is a link to the gradle changes documentation

How to fix "Rendering Problems The following classes could not be instantiated"?

I just started learning android coding and I keep getting this error:
Add these support library in build.gradle and also make sure the version of the support library(goto sdk manager and get the version number of sdk platform and place it in below dependancy because version of support library and sdk platform should be matched)
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
Try any of the following
Click refresh button on the preview pane
Sync Project with Gradle files
Click Tools > Android > Sync Project with Gradle Files
Rebuild Project
Click Build > Rebuild Project
This seems to come up periodically with Android Studio and it happened again today on an install I haven't used in a while. There may be more than one solution, but as of today June 08, 2016, I made sure two things are set:
1) Make sure you're on SDK/API 23 (or lower if necessary) vs the N preview, and
2) change the theme to "App theme". You may have to choose "Manifest Theme" in the left column before you can see "App Theme" show up as an option in the right column.
3) hit the refresh button (looks like two arrows in a circle)
Referring to a post above, both the support.appCompat and support.design libraries should be automatically added as dependencies to the gradle file, but you can double check them if necessary (and get the newest ones if the versions have changed).
You should see both of these:
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
Why Google and Jet Brains can't keep this from happening I don't know, but as of today, it cleared the problem right away.

How to check what is the latest version of a dependency to use in gradle

I've always added dependencies like this:
dependencies {
compile 'com.android.support:mediarouter-v7:19.+'
}
but in the recent versions of Android Studio, they recommend not to use the + as it can lead to errors. How to know what's the latest version? I can try every combination of 19.y.x until gradle complains, but what's the real way do check?
edit: sometimes, that page helps me figure it out.
There may be other ways, but here is what i use:
You can find out the latest version using Android Studio by replacing the version number of your library in build.gradle compile line, with just + , and click on Sync Now in upper right corner of the window.
in your case, for example
dependencies {
compile 'com.android.support:mediarouter-v7:+'
}
Android Studio will pop up a hint/bulb, which has options Replace with specific version you can click, which will fill-in the latest version in-place of +. Please see below screeshot:
If this doesn't work the first time, let gradle complete its sync, and retry (replace + with + or any file modification will do, click the sync now again and hint bulb will show up).
For example, for your library, i simply pasted this line compile 'com.android.support:mediarouter-v7:+' under my dependencies and followed the above process, Android Studio filled in with below version
Relying on latest version is indeed a dangerous thing to do. Your build can break without you changing anything, just because some library broke backwards compatibility.
The easiest way to know when new version of a library is out is to subscribe to new version notifications in Bintray.
Just click on the "Watch" button on the package page and you'll get an email every time new version is out. Then you'll be able to update the dependency, test it, and only then commit the build script with the new version.
As already mentioned by some other answers you should not use + in dependencies because it may lead to unpredictable builds, so its always better if you first test your builds once a new update is available.
With android studio 2.2 and above Project Structure will show you the latest dependencies available.
Activate it by going to Android Studio > Settings > Build,
Execution, Deployment > Gradle > Experimental and check the Use
new Project Structure dialog
Then open it by going to File >Project Structure > Messages
Original Answer
I use these two links.
This link gives me the latest buildTools Version
https://developer.android.com/studio/releases/build-tools.html
This link gives me the latest supportLibraryVersion
https://developer.android.com/topic/libraries/support-library/revisions.html
Recently, I have found this.
Go to File -> Project Structure
Select the Module, where you want to add the dependency.
Go to the Dependencies Tab
Click + and Choose Library Dependency
Choose whichever Library you need from the list.
(There is also an option for Search, never tried though.)
That's it.
Done.
Thank You.
Avoid to use + in version declare.
You can try andle to check if dependency out of date, also the build tool version and sdk version.
Simple three step:
1. install:
$ sudo pip install andle
2. set sdk:
$ andle setsdk -p <sdk_path>
3. update depedency:
$ andle update -p <project_path> [--dryrun] [--remote]
--dryrun: only print result in console
--remote: check version in jcenter and mavenCentral
the answer of ashoke is correct if you want the latest version.
But if you just want to replace "+" by the version you are currently using (therefor protection yourself against bug in future update)
eg:
compile 'com.android.support:appcompat-v7:21.0.+'
to
compile 'com.android.support:appcompat-v7:21.0.3'
(but not using 23.0.1)
this is the easiest way, no software needed:
run
$ ./gradlew clean tasks --debug > ~/whatever.txt
then look for "com.android.support:appcompat-v7:21.0."
a few line below you will see
"Using com.android.support:appcompat-v7:21.0.3 from Maven repository"
If it is a dependency that comes from Google's maven repository, the best way these days is to go to https://maven.google.com , where google now lets you browse all their libraries and see all the versions available, including the latest version. It looks like this:
You can even do a search for a specific library, and then expand/collapse it as desired:

Categories

Resources