I'm struggling with a strange issue.
I tried everything to find a solution to why my app crashes.
The reason is "implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.7.0' ".
When I add this implementation I get error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.myarcore/com.example.myarcore.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class
"com.example.myarcore.MainActivity" on path: DexPathList[[zip file
"/data/app/com.example.myarcore-Aw
This is my app gradle code:
apply plugin: 'com.android.application'
apply plugin: 'com.google.ar.sceneform.plugin'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myarcore"
minSdkVersion 26
targetSdkVersion 28
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
According to MultiDex documentation if app min sdk is higher than 21 then to enable MultiDex all I need is to put multiDexEnabled true as I did.
SOLVED,
My min SDK was set to 26.
Just add this to your app gradle, even when documentation says that is necessary in min SDK lower than 26.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Related
I have a device with android version 10.
Also, I have an emulator with API 22
this is a part of my build.gradle(:app) file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
dataBinding {
enabled = true
}
compileSdkVersion 'android-R'
defaultConfig {
applicationId "com.example.android.sOnline"
minSdkVersion 17
targetSdkVersion 'R'
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
// android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
}
}
It just not working on 'android-R'
Thank you for helping me :)
targetSdkVersion "R" will restrict your app to only running on Android R, by artificially raising your minSdkVersion to R. This has been the case for the past several years: each developer preview only supports running the app on the developer preview itself, not older devices.
Sometime later this year, we will be able to switch to using targetSdkVersion 30, at which point normal behavior returns with respect to minSdkVersion.
Go to build.gradle file
in defaultConfig: change minSdk to 28 and targetSdk to 30
I use a samsung s9 plus, had the same problem and now it works
defaultConfig {
applicationId "com.example.consigness"
minSdk 28
targetSdk 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
For me it was that the virtual device was corrupted , to fix this follow these steps :
open the AVD manager from the top right corner.
delete the device from the actions menu.
create a new one.
choose the new device and run your application.
For future safety before exiting the android studio make sure to close the emulator first.
Hi I am using CameraX api to build custom camera, after adding updated library dependency to build.gradle file, i am getting following build error
Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [androidx.camera:camera-extensions:1.0.0-alpha08] /Users/.gradle/caches/transforms-2/files-2.1/f20dc98c605a4c4dbd6030601f9665d3/camera-extensions-1.0.0-alpha08/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="androidx.camera.extensions" to force usage (may lead to runtime failures)
build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId ""
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
flavorDimensions 'dimensions'
productFlavors {
dev {
//assembleDevDebug crashlyticsUploadDistributionDevDebug
applicationId ""
versionName "D(0.0)" //for QA Release
versionCode 00
proguardFile("proguard-rules.pro")
}
prod {
applicationId ""
versionName "1.3" //for prod release
versionCode 13
proguardFile("proguard-rules.pro")
resValue "string", "app_name", "Prod Android"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.camera:camera-core:1.0.0-beta01"
implementation "androidx.camera:camera-camera2:1.0.0-beta01"
implementation "androidx.camera:camera-extensions:1.0.0-alpha08"
}
apply plugin: 'com.google.gms.google-services'
You can stick to your minimum version 16 by adding the following to your manifest file.
<uses-sdk tools:overrideLibrary="androidx.camera.view, androidx.camera.camera2, androidx.camera.lifecycle, androidx.camera.core"/>
To avoid runtime failures you'll need to check if the device is running on api 21 and above before using CameraX
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
// Use camera2 or cameraX
}else{
// Use Camera1
}
Update your app.gradle minSdkVersion
from:
minSdkVersion 16
to:
minSdkVersion 21
I imported the opencv android library to my android studio and the Camera2Renderer class has a lot of compiler errors because the android.hardware.camera2 classes can't be imported.
I solved the problem. Jim was right, I did not have the correct target API. For the next person who has this problem and finds this thread, the solution is that you have to make sure that the build.gradle files for your project and your OpenCV match.
I am working with openCVLibrary3.2.0 and trying to run its sample and faced same issue but I changed gradle files for both mysampleApp and openCVLibrary320 module as below
This is my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "org.opencv.face"
minSdkVersion 9
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
ndk {
moduleName "native_sample"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
dependencies {
compile project(path: ':openCVLibrary320')
}
and this my OpenCV library module build.gradle file
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Note:
things to notice are that compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion these must be same for all gradle files
I changed the compileSdkVersion from 14 to 23
and buildToolsVersion to "23.0.2"
this solved the camera2 import related issue
I am working on openCVLibrary330 trying to run its sample and faced same issue but i changed gradle files for openCVLibrary330 module as below
This is my app build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
I had the same problem. But, as many people have suggested I didn't had to change the gradle files to match exactly the same. I changed my compileSdkVersion and buildToolsVersion to the same on both gradle files, the rest are different. Its working fine now.
I just upgraded my Android Studio to 1.4.1.
In build.gradle, When i change my versionCode,
import org.apache.commons.lang3.JavaVersion
gets added to the top of build.gradle, which causes the error:
build file '/../app/build.gradle': 1: unable to resolve class org.apache.commons.lang3.JavaVersion
# line 1, column 1.
import org.apache.commons.lang3.JavaVersion
When I remove the line import org.apache.commons.lang3.JavaVersion, it gets added back automatically after a while.
When I revert the versionCode back to 1, the import statement disappears and all is well.
Gradle File
import org.apache.commons.lang3.JavaVersion
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "com.x.app"
minSdkVersion 14
targetSdkVersion 22
versionCode 2
versionName "1.0.1"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
How do i solve this issue?
Thanks!
Simply remove the import.
Your versionCode line in build.gradle should look like this :
versionCode 3
You use this class on compileOptions. That has nothing to do with pour versionCode, which is just fine.
Java 8 is not supported in Android, so I guess your problem is here
Im really stuck whit this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':External-Module')
}
I dont know what to do... I cant build project and use dependencies from External module.
the error is:
Error:(7, 47) error: package com.example.android.transfer does not exist
Error:(19, 9) error: cannot find symbol class ClientData
Error:(19, 25) error: cannot find symbol variable ClientData
Error:Execution failed for task ':Testing:compileDebugJava'.
but inside the IDE all is well and I can see the module
Here is also the External Module
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.externalmodule"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
}
Your "External-Module" is an Android library, so according to the Gradle+Android documentation instead of
apply plugin: 'com.android.application'
it should be
apply plugin: 'com.android.library'
// Old version of the plugin
// apply plugin: 'android-library'
Also, make sure the imports in your app matches the package you are overriding in your library build script. Looks like the app is not founding com.example.android.transfer but the library package really is com.example.externalmodule