Unresolved reference everything when i create new jetpack compose project - android-studio

i found some broke problem here, this is new project with default sample code I haven't do anything with the code then my android studio looks like in the image
I've try a lot of things including uninstalling android studio and re-installing this android studio, but I still found the same problem
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "id.rizki.nidelist"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
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
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}

You're not using the correct dependency versions. Most importantly, you are not using the correct version of Kotlin or Java:
In your project grade file use this:
buildscript {
ext {
compose_version = '1.1.0-beta01'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
}
}
In your app's gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.10'
}
apply from: 'codeinc.gradle'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 31
versionName "1.0"
//def yourVersionCode = getIncrementedVersionCode()
versionCode 1
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
useIR = true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.31'
}
}
dependencies {
def lifecycle_version = '2.4.0'
def activity_version = '1.4.0'
def retrofit_version = "2.9.0"
def paging_version = '3.1.0-beta01'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0-rc01'
implementation 'com.google.android.material:material:1.5.0-alpha05'
implementation "androidx.activity:activity-ktx:$activity_version"
implementation "androidx.activity:activity-compose:$activity_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-rc01"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
}

Related

No signature of method: org.gradle.api.tasks.bundling.Jar.destinationDir()

I'm getting this error
What went wrong:
A problem occurred evaluating root project 'android'.
A problem occurred configuring project ':app'.
Could not create task ':app:packLibsflutterBuildDebug'.
> No signature of method: org.gradle.api.tasks.bundling.Jar.destinationDir() is applicable for argument types: (File) values: [/Users/amjadkhoulani/Downloads/food_app12amjad/build/app/intermediates/flutter/debug]
build.gradle
buildscript {
ext {
kotlin_version = '1.5.0'
}
repositories {
google()
jcenter()
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
defaultConfig {
// Required by the Flutter WebView plugin.
minSdkVersion 21
}
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.food_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 20
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
debug {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
build{
manifestPlaceholders = [applicationName: "android.app.Application"]
}
}
}
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
android {
compileSdk 33
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.abc.test"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'kotlin-android'
apply plugin: "kotlin-android-extensions"
androidExtensions {
experimental = true
}
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
flutter {
source '../..'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'
implementation 'com.google.android.material:material:33'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
......................
This can happen if your gradle dependencies are out of date or out of sync.
android/build.gradle
Find the most recent, stable version of com.android.tools.build from here and update your dependencies:
dependencies {
...
classpath 'com.android.tools.build:gradle:7.4.1'
}
android/gradle/wrapper/gradle-wrapper.properties
Find the most recent stable version of Gradle from here and update the distribution URL.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip

How to solve undefined refrence error on android libtorch?

i got some issue on android libtorch
when i build my project, it always says to "C/C++: C:/Users/Administrator/AndroidStudioProjects/CardFinder/app/src/main/cpp/native-lib.cpp:26: error: undefined reference to 'torch::cuda::is_available()'"
i've never seen that before on visual studio
here's my android studio setting
'Cmake'
cmake_minimum_required(VERSION 3.18)
project(cardfinder)
set(CMAKE_CXX_STANDARD 14)
set(pathInclude ${CMAKE_SOURCE_DIR}/include)
add_library(native-lib SHARED ${CMAKE_SOURCE_DIR}/native-lib.cpp)
file(GLOB OPENCV_INCLUDE_DIRS "${pathInclude}/opencv")
file(GLOB PYTORCH_INCLUDE_DIRS "${pathInclude}/libtorch")
file(GLOB PYTORCH_API_DIRS "${pathInclude}/libtorch/torch/csrc/api/include")
file(GLOB SOURCE_INCLUDE_DIRS "${pathInclude}/source")
file(GLOB LINK_DIRS "${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
include_directories(
${OPENCV_INCLUDE_DIRS}
${PYTORCH_INCLUDE_DIRS}
${PYTORCH_API_DIRS}
${SOURCE_INCLUDE_DIRS})
find_library(
OPENCV_LIBRARY opencv_java4
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(
PYTORCH_LIBRARY pytorch_jni
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(
FBJNI_LIBRARY fbjni
PATHS ${LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
find_library(log-lib log)
target_link_libraries(
native-lib
${OPENCV_LIBRARY}
${FBJNI_LIBRARY}
${PYTORCH_LIBRARY}
${log-lib}
)
'build.gradle'
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.main.cardfinder"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags '-std=c++14'
}
}
ndkVersion "21.1.6352462"
}
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.18.1'
}
}
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'
def cameraxVersion = "1.1.0-alpha05"
implementation "androidx.camera:camera-core:${cameraxVersion}"
implementation "androidx.camera:camera-camera2:${cameraxVersion}"
implementation "androidx.camera:camera-lifecycle:${cameraxVersion}"
// CameraX View class
implementation 'androidx.camera:camera-view:1.0.0-alpha25'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
'my current project'

Unresolved Reference: mockwebserver

I'm writing a test suite with mockwebserver. I entered all of the dependencies from the official github page. Every time I try to run the test I receive Unresolved reference: mockwebserver
There's no option to import. The lettering isn't red on the import. Android Studio doesn't prompt anything. There are no other errors aside from ones related to the unresolved reference.
Screenshot:
build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id("org.jetbrains.kotlin.android.extensions")
}
android {
compileSdk 31
useLibrary("android.test.runner")
useLibrary("android.test.base")
useLibrary("android.test.mock")
defaultConfig {
applicationId "com.example.moviespotter"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
kotlinOptions {
jvmTarget = '1.8'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = '1.8'
}
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
testImplementation 'junit:junit:4.13'
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.10.0' //Glide
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "io.coil-kt:coil-compose:1.3.1"
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
androidTestImplementation 'com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'
}
Since this is in androidTest, it should be
androidTestImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
Also mixing 5.0.0-alpha.2 and 4.3.1 is a world of hurt.
I found the culprit.
When adding the dependency to the build.gradle file it should read implementation.
Change From:
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
To:
implementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

Android Studio: Error "Failed to resolve: design"?

Hi I receive this error message on gradle project sync.
"Failed to resolve: design"
I can't find what's this.
Is there any friend that can help me with this? Or do you have another icon pack Android Studio project?
It's from CandyBar-Sample-Master android icon pack project.
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.CompileSdk
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def appName = parent.name
def fileName = appName.replace(" ", "_")
outputFileName = "$fileName-v${variant.versionName}.apk"
}
}
defaultConfig {
applicationId "com.grafiman.icons.selero"
minSdkVersion rootProject.ext.MinSdk
targetSdkVersion rootProject.ext.TargetSdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.danimahardhika.candybar-library:core:3.5.0-b4'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
google()
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
}
//NOTE: This is important
rootProject.ext {
BuildTools = "27.0.3"
MinSdk = 15
TargetSdk = 26
CompileSdk = 26
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Error:Cannot read packageName from E:\Lins\ZXing_luolu\ZxingScan-master\zxing-zxing-3.3.0\src\main\AndroidManifest.xml

.png is my code short cut
I'm failed to Import third-party source libraries
//following are my build.gradle file
//app module
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.meng.zxingscan"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':zxing-zxing-3.3.0')
// compile files('libs/core-3.3.0.jar')
}
//zxing module
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.meng.zxingscan"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v7:18.+'
}

Resources