can you help me with this error in android studio? - android

I'm trying to run a project that is using a C++ module i try everything and nothing works it still get this error.
Error:Execution failed for task ':pulseandroid:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
https://developer.android.com/studio/build/experimental-plugin.html.

1 - Make sure NDK is install
2 - Put this part in build.gradle(Module:app) above buildTypes{}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{}

Related

Android : Run CMake manually via gradle

I am working on an android project which use C++ code.
I have added required CMake settings in build.gradle:
externalNativeBuild {
cmake {
path file('jni/CMakeLists.txt')
version '3.18.1'
}
}
But the problem is there are a lot of C++ files. Using gradle for build makes Android Studio index those files and it makes IDE very slow.
Is there a way to invoke CMake task manually outside IDE so that IDE don't index them? Actually what I want is to use a gradle task to build native code via CMake.

How to make android-app-module identify and use gradle-plugin-module sources

I've created a standalone plugin along with a simple demo app, that I need for development. Both are added to the same project as an app-module and a plugin-module, so that I can easily develop and test features I write in the plugin. I'm assuming that if I add the sources from the plugin to buildSrc/build.gradle.kts, I'll be able to reference the plugin sources from the app (I need that to build and apply the plugin). The demo project in its entirety can be found here: https://github.com/oizo/gradle-plugin-sample.
Currently, it seems that when I apply the plugin in app/build.gradle.kts it's available (autocomplete is working) but when I try to build with ./gradlew build it fails with this message:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/MyUser/github/gradle-plugin-sample/app/build.gradle.kts' line: 10
* What went wrong:
Script compilation error:
Line 10: apply<io.hvam.android.plugin.StringPlugin>()
^ Unresolved reference: io
Clearly, I'm missing something.
I've tried the solution proposed in this post-https://stackoverflow.com/a/42263532/1181023, which seems to be a similar problem, but when I run ./gradlew build --include-build plugin/ it also fails to build, with the following:
FAILURE: Build failed with an exception.
* What went wrong:
Included build in /Users/MyUser/github/gradle-plugin-sample/plugin has a root project whose name 'plugin' is the same as a project of the main build.
I see two issues:
Your plugin must be packaged in such a way that your Plugin implementing class is visible to consumers of the plugin as the entry point. One easy way of doing that is by using gradlePlugin {} block. I would recommend to upgrade to at least Gradle 5.5.1 and use build init plugin to automate all these for you.
Please try gradle init --type kotlin-gradle-plugin to generate the plugin project. This would add code similar to below in your plugin build.gradle which ensures your consumers can apply the plugin using apply plugin: "stringPlugin".
gradlePlugin {
plugins {
stringPlugin {
id = "stringPlugin"
implementationClass = "com.example.StringPlugin"
}
}
}
Secondly, your plugin must be visible to the buildscript classpath so that it can apply your plugin. If you have already published the plugin to maven, then you can add the below in project level build.gradle to let gradle discover your plugin.
buildscript {
...
dependencies {
classpath "com.example:stringplugin"
}
}
Publishing to maven might not be convenient during development. You could utilize Gradle's composite builds to help in this regard. In your project level settings.gradle, add below:
includeBuild('./plugin') {
dependencySubstitution {
substitute module('com.example:stringplugin') with project(':plugin')
}
}
This instructs gradle to use locally present :plugin module when com.example:stringplugin is requested. This would be convenient for development.
It seems I misunderstood how gradle uses the buildSrc folder. I've moved the content of buildscript into buildSrc/build.gradle.kts but omitting the actual buildscript extension. This somehow fixed the issue of the app-module not being able to recognize the plugin sources when building. The specific changes related to the fix can be reviewed int this commit. And the sample code in the repo now builds as expected.
This gives some more clarity about the purpose of the buildSrc folder: https://stackoverflow.com/a/13875350/1181023

Android Gradle Build: duplicate entry: META-INF/app_release.kotlin_module

I'm trying to build a release app via Android Studio > Generate Signed Bundle or APK > Android App Bundle > Release
However gradle fails with
: > Task :core:transformClassesWithMergeClassesForRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core:transformClassesWithMergeClassesForRelease'.
> 1 exception was raised by workers:
java.util.zip.ZipException: duplicate entry: META-INF/app_release.kotlin_module
In my build.gradle I've tried adding:
packagingOptions {
exclude 'META-INF/app_release.kotlin_module'
}
But it isn't making any difference whatsoever.
How do I fix this?
For extra context, it's a multi module project.
I have a core module, and an installed module which is declared in the core build.gradle with dynamicFeatures = [":installed"]
Thanks
Please make sure all your dependencies are api or implementation,
I have the flowing dependency grap.
meemo_sdk:
api project(":gvoice")
app project:
implementation project(":gvoice")
implementation project("meemo_sdk")
It complains "META-INF/gvoice_debug.kotlin_module" collision.
After change api to implementation, it works!
So I figured it out.
I pressed shift twice in Android studio (to open up the search everywhere dialog) and searched for app_release.kotlin_module
I saw two files, that were under two of my dependencies (which funnily enough were libraries that I had created!)
I opened up these library projects, and in the build.gradle file I had to add:
ext {
PUBLISH_GROUP_ID = 'com.companyname'
PUBLISH_ARTIFACT_ID = 'packagename'
}
android {
...
compileOptions {
kotlinOptions.freeCompilerArgs += ['-module-name', "$PUBLISH_GROUP_ID.$PUBLISH_ARTIFACT_ID"]
}
}
Rebuilt the library projects with new versions, used these new versions in my other project, and it started compiling :)
Build -> Clean Project Worked for me
I found the same issue comes randomly by using Android Studio 4.2.1 and Java8, I sorted out successfully by deleting .gradle file in the project (not the main one) every time I get the error.
Java version: JDK8221
Kotlin: 1.5.0
AndroidStudio: 4.2.1
Not the best solution but is a good workaround for now.

Android Studio: Add .cpp file tree without building

Is it possible to add a tree of .h/.cpp files to the Android Studio editor for reference - so that they can be edited but not actually built/compiled by Android Studio?
I have JNI/NDK files which I want to build manually from the command line but I don't want Gradle/Android Studio to build these files.
There is a Gradle 'exclude' command/function which may be what I need but I cannot get it to work.
sourceSets {
main {
exclude 'jni'
//exclude ("jni/**")
//jni.srcDirs = []
}
}
I get the following error:
Error:(10, 0) Gradle DSL method not found: 'exclude()'
I didn't manage to figure this out with a vanilla Android Studio set-up but by using the Gradle Experimental Plugin I have ended up with the desired outcome. Once I got the 0.7.0 experimental plugin working (and my build.gradle configured for the new 'model' scoping), I was able to remove the sourceSets statement, successfull sync, edit within Android Studio and build from the command line via ndk-build.

NDK Integration in Android Studio Error

I am using Android studio version 1.3.1 and try to integrate the NDK by going to local.proprties and writing ndk.dir= and I got this error
Error:Execution failed for task ':tesstwo:compileReleaseNdk'.
Error: NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.
Please help me to sole this issue.
Add this to your build.gradle :
android{
sourceSets {
main {
jni.srcDirs = []
}
}
}

Categories

Resources