I got this fatal error , when I was trying to import opencv module to my project. Even Gradle sync is finished successfully, I have also tried invalidate cache and restart but it does not solved anything. And also went through some stackoverflow's solutions that too didn't work.
please help me finding the solution.
Error :
java.lang.NullPointerException
at com.android.tools.idea.gradle.adtimport.GradleImport.getBuildToolsVersion(GradleImport.java:1081)
at com.android.tools.idea.gradle.adtimport.GradleImport.createModuleBuildGradle(GradleImport.java:971)
at com.android.tools.idea.gradle.adtimport.GradleImport.exportModule(GradleImport.java:927)
at com.android.tools.idea.gradle.adtimport.GradleImport.exportProject(GradleImport.java:792)
at com.android.tools.idea.gradle.adtimport.AdtImportBuilder.lambda$commit$0(AdtImportBuilder.java:151)
at
...
java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle : app
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.project.opencv"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ''
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.10.2'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
CodePudding user response:
Add this code in app: gradle dependencies{}:
implementation fileTree(dir: 'libs', include: ['*.jar'])
And also add this in app: gradle android{}:
buildToolsVersion '32.0.0'
I hope it will help you.
CodePudding user response:
As @Younus pointed out, include this line inside dependencies { } :
implementation fileTree(dir: 'libs', include: ['*.jar'])
and this other line inside android { }
buildToolsVersion '32.0.0'