I am trying to setup a basic ndk build with the latest version of android studio at this moment. Trying to follow this tutorial
This is my gradle-wrapper.properties
#Thu Sep 17 14:22:34 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
This is the project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is my module's build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "me.blubee.testnative_exp"
minSdkVersion = 10
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
buildConfigFields.with {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
create("flavor1") {
applicationId = 'com.app'
}
}
android.sources {
main {
java {
source {
srcDir 'src'
}
}
}
}
}
}
my project structure looks like this:
APP
Java/
Java/android.support
Java/com.test.test_experimental
Java/com.test.test_experimental/R
Java/com.test.test_experimental
Java/com.test.test_experimentalBuildConfig
Java/com.test.test_experimental
Java/com.test.test_experimental/MainActivity
tests/
tests/com.test.test_experimental
tests/com.test.test_experimental/ApplicationTest.java
tests/com.test.test_experimental
tests/com.test.test_experimental/BuildConfig.java
resources/
test-resources
gradle/scripts/
I am getting these errors:
2:51:31 PM Gradle sync started
2:51:34 PM Gradle sync failed: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Consult IDE log for more details (Help | Show Log)
Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Brother:TestNative_exp blubee$ ./gradlew clean --stacktrack
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/bb/TestNative_exp/app/build.gradle' line: 10
* What went wrong:
A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.619 secs
line #10 is: minSdkVersion = 10
You can see the whole file in the build.gradle that i put above.
edit
As #unbekant pointed out in his comment and the link to this post
The min and target sdk values should be set like this:
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
I tried that as well, I get this error:
* What went wrong:
A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> No such property: buildConfigFields for class: com.android.build.gradle.managed.AndroidConfig
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
What am I doing wrong?
You have to put these blocks outside the android block.
android.buildTypes
android.sources
android.productFlavors
Also the buildConfigFields.with should be inside the defaultConfig or inside the buildTypes or productFlavors:
Something like:
model {
android {
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
defaultConfig.with {
//----
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 23
buildConfigFields.with {
create() {
//....
}
}
}
}
android.buildTypes {
release {
//
}
}
android.productFlavors {
//
}
// Configures source set directory.
android.sources {
//
}
}
Also, the last version is 0.2.1.
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
There's a tutorial? Oh, that. Where are the links?
The current version is 0.2.0.
or dates?
I googled every one of the missing files individually (maybe 3 dozen!) after adding:
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
I tried the alpha version too but I failed finding some of its dependencies altogether.
First I get a couple of dependencies I can be bothered chasing down:
> Error:Could not find com.android.tools.build:gradle-experimental:0.2.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.jar
Once each of these was added to the given path seven more would sprout up in its place. If someone could post how to automatically update these (they still aren't in the latest 1.4RC1 Android Studio) it would be very useful. I got most of the stuff from maven, eg http://mvnrepository.com/artifact/com.android.tools.lint/lint-checks/24.3.1
I got all the files to shut up Gradle's whining and you know what it said?
Error:(34, 1) A problem occurred evaluating project ':app'.
> 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.
Which was exactly the error that led me to migrate to experimental and no better than the stock 1.3.0 that ships with AS (though it was defaulting to 1.2.3).
Why did I bother? I want to debug NDK and couldn't see what else I wasn't doing apart from not using an experimental build.
This goose chase was just a big waste of time. I'm back to using
android.useDeprecatedNdk=true
No doubt I can fix it somewhere else but just a warning to others chasing experimental dependencies; they are unicorns.
#jonagon
Some examples are in this repo:
https://github.com/googlesamples/android-ndk
probably could try:
Use the latest plugin version. Find it at:https://jcenter.bintray.com/com/android/tools/build/gradle-experimental
check https://github.com/googlesamples/android-ndk/blob/master/hello-jni/app/build.gradle for product flavors
jni folder issue:
it is default for gradle experimental plugin, also for older c++ support NOT using gradle-experimental plugin ( android plugin )
if you have that folder and not using experimental plugin, Gradle thinks that app is using the older android studio c++ support. It gives your that warning "NDK integration is deprecated in the current plugin" and recommend you to experimental plugin. it could be silenced with:
sourceSets.main.jni.srcDirs = []
or just rename that jni folder to something else: it will cause more trouble if you want to android-studio cmake/ndk-build in the future, rename is better.
Related
I have tried many solutions but all in vain, including this
React Native Android build failure with different errors without any changes in code for past days due to publish of React Native version 0.71.0-rc.0
I am having deadline ahead and my project is not building from last 4 days, any help will be appreciated.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.activity:activity-compose:1.4.0.
AAR metadata file: /Users/dev/.gradle/caches/transforms-2/files-2.1/c35837abe789834d04f87678613d3ab9/jetified-activity-compose-1.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I have tried compileSdkVersion = 31
targetSdkVersion = 31
after that I am getting
Execution failed for task ':react-native-incall-manager:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
My build.gradle file is
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
androidXCore = "1.7.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
React native version is "^0.66.3"
Your app was working fine before right so, please follow below steps and check
Revert back all the changes you have made after that (if you changed versions of sdk, gradle, java, react-native etc)
Delete node_modules
Delete build folders (android/build & android/app/build)
Recheck the package.json if the react-native version is as which was worked before (in your case 0.66.3)
Run npm install or yarn to install packages
Clean (remove gradle cache like mentioned here : https://stackoverflow.com/a/30450020/10657559) and rebuild the app by adding the below changes to your android/build.gradle file
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
buildscript {
// ...
}
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
// ...
}
Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210
This is an issue from gradle servers. There are many official fixes being launched. You can either upgrade react-native to 0.70.5 or you can patch it using fix available here. https://github.com/facebook/react-native/issues/35249
It is causing due to some issue at react-native since friday, 4 Nov 2022.
Updating your react-native version can solve it.
Note: No need to update gradle files for this issue.
All fix version of RN are mentioned here.
Ex: if you are on 0.64.3, change to 0.64.4
ref: https://github.com/facebook/react-native/issues/35210
Unable to load class 'ijinit_dkec9zswd4p83aajh1klyj0h5'. (React_native gradle sync issue)
I am facing this issue on Gradle sync while building .apk, dubug apk is working fine.
I have also cleaned Gradle and rebuilt my app but still no improvement.
Error image
Build Script:
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "21.4.7075529"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Error:
Unable to load class 'ijinit_dkec9zswd4p83aajh1klyj0h5'.
This is an unexpected error. Please file a bug containing the idea.log file.
FAILURE: Build failed with an exception.
What went wrong:
Could not load compiled classes for initialization script 'C:\Users\User\AppData\Local\Temp\ijinit.gradle' from cache.
ijinit_dkec9zswd4p83aajh1klyj0h5
Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Exception is:
org.gradle.api.GradleException: Could not load compiled classes for initialization script 'C:\Users\User\AppData\Local\Temp\ijinit.gradle' from cache.
Caused by: java.lang.ClassNotFoundException: ijinit_dkec9zswd4p83aajh1klyj0h5
Had a similar error, fixed it by upgrading Android Studio. It needed a proper sync after upgrade.
Refer to https://issuetracker.google.com/issues/36990380
Update will solve your problem
Help -> Check for Updates
Every time I try to run my project, clean it or build it I get a gradle error:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Task 'compile' is ambiguous in root project 'FifiFun2'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources', 'compileLint', 'compileReleaseAidl', 'compileReleaseJavaWithJavac', 'compileReleaseNdk', 'compileReleaseRenderscript', 'compileReleaseSources', 'compileReleaseUnitTestJavaWithJavac', 'compileReleaseUnitTestSources'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I have tried running gradle tasks with the options above (stacktrace,info,debug) but nothing helpful came up.
gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
main gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.user_pc.myapplication"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}
settings.gradle file:
include ':app'
Screenshot of the problem:
The problem is, your gradlew file is in the root of your project and you are trying to run an ambiguous task compile from the root of the project, in which the compiler does not know the actual task to run, this will lead to TaskSelectionException. You can run a single task, this stackoverflow question will help you
Check the following :
Can you build and run another project? (New one for instance).
Try defining a debug buildType and resync gradle then build.
Check if you have a good proyect structure or set it in gradle.build if you don't.
If non of thoses work am out of ideas, sorry.
Remove the code
task clean(type: Delete) {
delete rootProject.buildDir
}
from your gradle file, then clean and rebuild your project.
None of the above worked for me. The solution I found was
Install latest version of Cordova.
Install latest version of gradle. You can do this Manually. Remember to updated GRADLE_HOME and PATH in System variables
Remove and reinstall android in your project. Remember to back up items such as Icons etc
Run cordova build android --prod --release. This will generate an App bundle instead of an APK file. This command will also hopefully download the latest version of gradle for your project.
Hope that helps some poor soul somewhere who is at their wits end.
You need to clean the project(Top level menu Build --> Clean Project) first and then run the command again.
I am trying to integrate the Google Play Game Services with my project. I have added the play services as a dependency to my build.gradle, but when I try to rebuild the project I get this error:
* What went wrong:
A problem occurred configuring project ':android'.
> Could not resolve all dependencies for configuration ':android:_debugCompile'.
> Could not find com.android.support:support-v4:19.0.1.
Required by:
Taxi Trouble:android:1.0 > com.google.android.gms:play-services:4.3.23
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
According to the SDK manager I have version 19.1, instead of the required 19.0.1. Can I install this older version of the support library?
Please share your build.gradle file. The following example, taken from an update to the Play-Google Play Games Services GitHub pages, shows a working build.gradle file with the latest support library.
First, note that there are multiple build.gradle files and settings.gradle files in a particular project/workspace. Let's focus on the two most likely candidates for breaking your build.
root (build.gradle) (e.g. root/build.gradle)
Android module for your app (e.g. root/module/build.gradle)
Root project build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
build.gradle from within a project module:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
//compile project(':libraries:BaseGameUtils')
}
buildscript {
repositories {
mavenCentral()
}
}
repositories {
}
}
It's a little confusing at first but your gradle build library version must match your ADT version which must match your GMS version. As Android Studio stabilizes, required updates to match configurations across tools and Android libraries will hopefully become less common.
Hi I have set up my Android project on Jenkins to provide CI. Its working well, running tests on a connected Android handset. The tests run on the Android Test Framework which extends jUnit3.
Unfortunately, the build is marked as a failure if there are any test failures. I'd like to be able to improve this in two ways:
Allowing unstable builds
Being able to mark known test failures
For item 1 I tried adding this to the project build.gradle:
connectedCheck {
ignoreFailures = true
}
But it has no effect. Looking at the build log, I realised the actual test task is called connectedInstrumentTest, but this task is not found:
connectedInstrumentTest {
ignoreFailures = true
}
causes:
Could not find method connectedInstrumentTest() for arguments [build_4ldpah0qgf0ukktofecsq41r98$_run_closure3#9cd826] on project ':Playtime'.
That am I missing?
Thanks
EDIT: Heres my project build.gradle, nothing special:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
testPackageName "com.bb.pt.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
}
connectedCheck {
ignoreFailures = true
}
My gradle settings in jenkins:
switches: --stacktrace --info
tasks: :pt:assembleDebug :pt:assembleTest :pt:connectedCheck
EDIT:
I built gradlew and tried that. Same output. I don't want the build to FAIL if there are test failures:
:pt:connectedInstrumentTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':pt:connectedInstrumentTest'.
> There were failing tests. See the report at: file:///home/simon/WorkingCopies/bb/code/trunk/pt/pt/build/reports/instrumentTests/connected/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
I tried to qualify the task name in build.gradle:
task connectedCheck {
ignoreFailures = true
}
But it thinks I am trying to add a new task rather than modify the existing one.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/simon/WorkingCopies/bb/code/trunk/pt/pt/build.gradle' line: 31
* What went wrong:
A problem occurred evaluating project ':pt'.
> Cannot add task ':pt:connectedCheck' as a task with that name already exists.
After our conversation I believe that:
the problem is gradle configuration only and not jenkins related. Get it to work in gradle.
in gradle I believe (though I am not an expert) you should get the connectedInstrumentTest to ignore failures, but your attempt to use the following failed
connectedInstrumentTest {
ignoreFailures = true
}
maybe the solution is to wrap this config node like this:
project.gradle.taskGraph.whenReady {
connectedInstrumentTest {
ignoreFailures = true
}
}
https://github.com/stanfy/hotandroid/blob/master/part0/build.gradle