Android studio 2.1 editor(CLint) unable to find headers of modules that use native(ndk) plugin - android-studio

It looks like the AndroidStudio 2.1 editor highlights the header file from a native module red as though it is missing. It seems to build and run with no issues though. Anyone facing the same issue? (See attached images below)
Also the editor suggests that I include Addition.h using the long relative path. Adding the header file location with cppFlags does not seem to fix this issue.
app build.gradle
apply plugin: 'com.android.model.application'
model {
android {
.......
ndk{
moduleName = 'native'
}
sources {
main {
jni {
dependencies {
project ':Addition' linkage 'static'
}
}
}
}
}
}
Addition module build.gradle
apply plugin: 'com.android.model.native'
model {
android {
........
ndk {
moduleName = 'addition'
}
sources {
main {
jni {
exportedHeaders{
srcDir "src"
}
source {
srcDir "src"
}
}
}
}
}
}
Steps to Reproduce: https://github.com/noridge/StudioClintBug
Studio Build: 2.1.1
Version of Gradle Plugin: experimental 0.7.0 and 2.1.0
Version of Gradle: 2.10
OS: MacOSX El Capitan 10.11.4

Filed a bug with Google. They seem to have fixed it in 2.2
https://code.google.com/p/android/issues/detail?id=209865

Related

This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31

I'm using the latest Android Studio and I'm able to build and run my app fine with compose_version set to 1.0.5. However, I'd like to use the latest stable compose version 1.1.1.
I try to simply update the project build.gradle so it contains the following pointing to the desired compose version and the corresponding compatible kotlin version. These values are referenced in the app's build.gradle.
buildscript {
ext {
compose_version = '1.1.1'
kotlin_version = '1.6.10'
}
And in Android Studio, I go to Tools > Kotlin > Configure Kotlin Plugin Updates and download the latest Kotlin plugin (Early Access).
If I open Tools > Kotlin > Kotlin REPL, I see Welcome to Kotlin version 1.7.0-RC2-release-258 (JRE 11.0.12+0-b1504.28-7817840).
Now, I try to Rebuild Project.
I get the error:
This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
I don't wish to suppressKotlinVersionCompatibilityCheck given the warning, but I even tried that option and got other build errors.
Why is Kotlin version 1.5.31 being used? Shouldn't updating the Kotlin plugin have gotten Android Studio to switch to a more recent Kotlin version (as suggested by the Kotlin REPL message)? How can I make it such that Kotlin 1.6.10 is used and I stop getting the error?
Got the same error when using Compose 1.1.1. and Kotlin 1.7.0.
Task :app:compileDebugKotlin FAILED
e: This version (1.1.1) of the Compose Compiler requires
Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.0
which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Changed the below block in my build.gradle (app module)
composeOptions {
kotlinCompilerExtensionVersion 1.2.0
}
This is my plugins block in build.gradle (project):
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}
This Android developers page helped with picking the compatible versions :-
Compose to Kotlin Compatibility Map
Don't forget to sync and rebuild.
Compose uses the kotlin compiler defined in your buildscript block:
buildscript {
ext.kotlin_version = '1.6.10'
//....
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
If you are using the plugins block in settings.gradle or build.gradle:
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10'
}
}
Using this help me.
build.gradle (:app)
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
There are 3 things you need to ensure are in sync(compatible with the other) for kotlin to work properly.
1)compose_ui_version='1.2.1' of buildscript in build.gradle(project)
2)plugin 'org.jetbrains.kotlin.android' version '1.7.10' in build.gradle(project)
3)kotlinCompilerExtensionVersion '1.3.1' in composeOptions in build.gradle(app)
To get the latest version of compose compiler and its corresponding kotlin version check here.
for me what I had to edit is to locate build graddle(Project):
first load compose_version to see the latest stable compose_version.
buildscript {
ext {
//2. change here to the latest stable (compose_version) that you got in step 1
compose_version = '1.3.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
//when you run you app, The next error will tell you the version of Kotlin that the latest compose_version needs, edit as below to the version required in the error
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
and build.gradle(Module)
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
Go to your project level build.gradle file
There in the plugin section below mentioned 2 libraries has to be in the same version to remove this error:
{
...
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
}
If required, change:
compileSdk 33
&
targetSdk to 33
. (inside app level build.gradle file).
Now sync the project & reload the priview. It will work fine.

Node Build fail after upgrade to Gradle 7.3

We have upgrade gradle from 4.8 to 7.3 after that nodeSetup build gets fail with below error.
Could not find method layout() for arguments [pattern, com.moowork.gradle.node.task.SetupTask$_addRepository_closure5$_closure7#25995910] on object of type org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository.
Below are code snippet of build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.moowork.gradle:gradle-node-plugin:1.3.1"
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
}
}
apply plugin: "com.moowork.node"
apply plugin: "io.spring.dependency-management"
node {
version = "16.13.12"
npmVersion = "6.12.0"
download = true
nodeModulesDir = file("/XXX")
}
Cause:
There is a breaking change in gradle 6.8 which is you can checkout here:
https://docs.gradle.org/current/userguide/upgrading_version_6.html#configuring_the_layout_of_an_ivy_repository
"The 'layout' method taking a configuration block has been removed and
is replaced by 'patternLayout'
Your plugin "com.moowork.gradle:gradle-node-plugin:1.3.1" is using that method which not upgraded in this library.
Solution:
You can use this gradle-node-plugin instead of "com.moowork.gradle:gradle-node-plugin:1.3.1"
Installation:
https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/installation.md
Installing the node-related plugins can be done in multiple ways. The easiest is to use the plugins-closure in your build.gradle file:
plugins {
id "com.github.node-gradle.node" version "3.1.1"
}
You can also install the plugins by using the traditional Gradle way:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "com.github.node-gradle:gradle-node-plugin:3.1.1"
}
}
apply plugin: 'com.github.node-gradle.node'

How to reduce build variants of native library in Android Studio 3.3?

In Android Studio 3.2.1 I had two build variants visible for my native library; Release and Debug. In 3.3 I get a combination of these and all ABIs. I don't want to build multiple APKs for all the ABIs.
The relevant parts of the native library project:
apply plugin: 'com.android.library'
android {
defaultConfig {
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
release {
}
debug {
}
}
externalNativeBuild {
ndkBuild {
path 'jni/Android.mk'
}
}
sourceSets {
main {
java.srcDir generatedSrcDir
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
}
Build warnings
Maybe unrelated, but I observed this warning in the Build log (actually twice in a row):
WARNING: ABIs [arm64-v8a,armeabi-v7a,armeabi] set by
'android.injected.build.abi' gradle flag contained 'ARMEABI' not
targeted by this project.
How do I get back to the old behavior?
Apparently this is an intentional change: see this issue.
According to the linked ticket, this is only "cosmetic"(ie a UI change); a full/fat .apk is still built.

error: package org.hamcrest does not exist Android Studio 1.5.1

I am using Android studio 1.5.1.
My build.gradle looks like below
allprojects {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
dependencies {
// Unit testing dependencies
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'junit:junit:4.12'
}
I am writing some JUNIT test cases for my application as below
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public void testSomething throws Exception {
...
assertThat(result, is(true));
}
But when I am running the tests, it is showing that
error: package org.hamcrest does not exist
error: cannot find symbol assertThat(result, is(true));
But I can go to the definition of assertThat, org.hamcrest etc from studio by going to definition as studio decompiles the jars.
Also I can see the package downloaded in .gradle/caches
Can anyone suggest what I am doing wrong here?
Normally Junit test cases using assertFalse, assertTrue etc is working, only hamcrest matching is giving errors.
Manually add the jar from here
Add it to your libs folder.
Right click the jar, and click add as library.
I had the same issue with getting it to find junit. Looks like Gradle is not doing its job.
I have filed a bug report, Please star:
https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330

NDK support deprecated for Android Studio 1.1.0

Currently running Android Studio 1.1.0. Installed NDK and added the link to the build.gradle file. Building the project gives a trace with the following text.
WARNING [Project: :app] Current NDK support is deprecated. Alternative will be provided in the future.
android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 1
Is NDK r10d unsupported by Android Studio?
The current NDK support is still working for simple projects (ie. C/C++ sources with no dependency on other NDK prebuilt libraries), including when using the latest r10d NDK.
But it's really limited, and as the warning says, it's deprecated, yes.
What I recommend to do is to simply deactivate it, and make gradle call ndk-build directly. This way you can keep your classic Android.mk/Application.mk configuration files, and calling ndk-build from your project will still work the same as with an eclipse project:
import org.apache.tools.ant.taskdefs.condition.Os
...
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files location to libs instead of jniLibs
jni.srcDirs = [] //disable automatic ndk-build call
}
// add a task that calls regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
// add this task as a dependency of Java compilation
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
I use the method below to construct the ndk-build absolute path:
def getNdkBuildExecutablePath() {
File ndkDir = android.ndkDirectory
if (ndkDir == null) {
throw new Exception('NDK directory is not configured.')
}
def isWindows = System.properties['os.name'].toLowerCase().contains('windows')
def ndkBuildFile = new File(ndkDir, isWindows ? 'ndk-build.cmd' : 'ndk-build')
if (!ndkBuildFile.exists()) {
throw new Exception(
"ndk-build executable not found: $ndkBuildFile.absolutePath")
}
ndkBuildFile.absolutePath
}
Used as:
commandLine getNdkBuildExecutablePath(), '-C', ...
Now Android Studio 1.3 at Canary channel fully supports NDK. Try it. Reference: http://tools.android.com/download/studio/canary/latest

Resources