cant import dependency implementation on android studio - android

I am beginner to android studio and I am trying to import a remote dependency for a library of DatePickerDialog (link for its github) but the import doesn't work for me.
I tried to import it by the Group Id (com.github.wdullaer) and Artifact Name (MaterialDateTimePicker) as it shows in the ProjectStructure/dependencies
I tried - import com.github.wdullaer.MaterialDateTimePicker
I also tried - import com.wdullaer.MaterialDateTimePicker
and more but the import does not work
but
here is my gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and here is the DateTimePicker implementation:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.speedq"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'com.github.wdullaer:MaterialDateTimePicker:v4.2.3' // this is the implementation I cant import
}
if any one knows how can I import it it will be very helpful

that is wrong:
implementation 'com.github.wdullaer:MaterialDateTimePicker:v4.2.3'
first of all dont use v near version, so just remove it
also you got wrong path, read again guide - you should use this:
implementation 'com.wdullaer:materialdatetimepicker:4.2.3'

Related

Exception in plugin Android

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'
}

How to fix the "Android MPAndroidChart Could not find method dependencyResolutionManagement() for arguments error in gradle"?

well Im trying to use MPAndroidChart library in Android studio
my gradle version was 7.0.2 but it didnt work well.
so i changed gradle Version to 6.7.1, and Android Gradle Plugin Version to 4.2.2
i also changed the version of sdk to Android 11.0(R)
my Target SDK version is 30
--build.gradle(project)
// 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:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects{
repositories{
google()
mavenCentral()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(Module)
plugins {
id 'com.android.application'
}
android {
compileSdk 31
BuildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories{
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "My Application"
include ':app'
--capture of the bug
enter image description here
--bug code
Settings file 'C:\Users\kimta\AndroidStudioProjects\MyApplication\settings.gradle' line: 1
A problem occurred evaluating settings 'MyApplication'.
Could not find method dependencyResolutionManagement() for arguments [settings_5pc4jcjs87c9dkfx5manehm0u$_run_closure1#69c68d91] on settings 'MyApplication' of type org.gradle.initialization.DefaultSettings.
gradle problem is too difficult for novice like me. Is there any solution ?
You try to add this line in your settings.gradle:
maven { url 'https://jitpack.io' }
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' } //Add this line in your settings.gradle
}
}
rootProject.name = "My Application"
include ':app'
--build.gradle(project)
// 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"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(Module)
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// MPAndroidChart
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}

Could not GET 'https://dl.bintray.com/guardian/android/androidx/compose/compose-compiler/1.0.0/compose-compiler-1.0.0.pom'

I'm trying to setup jetpack compose for an existing project but i'm having the above error when i trying to run the app after synchronized the gradle files.
This is how my build.gradle (project) looks like:
buildscript {
ext.kotlin_version = '1.5.10'
ext.compose_version = '1.0.0'
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
}
}
plugins {
id "com.github.hierynomus.license" version "0.14.0"
}
....
and this is how my build.gradle(Module) looks like:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.app.schedulicity"
minSdkVersion 21
targetSdkVersion 30
versionCode 82
versionName "10.0.9"
renderscriptSupportModeEnabled true
multiDexEnabled true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
// Room migration helper: expose the schema
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}
// Room migration testing: adding the schema location as an asset folder
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
String sharedTestDir = 'src/sharedTest/java'
debugTesting {
java.srcDir sharedTestDir
resources.srcDirs += ['src/test/resources']
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
buildFeatures {
compose = true
viewBinding true
}
composeOptions {
kotlinCompilerVersion = "1.5.10"
kotlinCompilerExtensionVersion = "1.0.0"
}
kotlinOptions {
jvmTarget = "1.8"
}
....
If i synch the project all looks good but when i try to compile then the error happens. As you can see i haven't include any dependency to the project yet.
Maybe some of you have faced with this problem before and have a solution :)
Of course the error will occur. The error does not occur in sync since there is nothing wrong with the added dependencies. Everything is downloaded and works fine. When you try to compile, it doesn't because you have not added the compose compiler dependency. How would it compile when the compiler itself is missing?
Create a dummy project using the studio templates and copy the dependencies from there.
Or visit here
https://developer.android.com/jetpack/compose/interop/adding

Why is Kotlin's mutableListOf() returning a null value

I am working through Google's Android developer codelab for the the unscramble app. I am trying to initialize my variable wordsList to be an empty mutable list of strings with:
private var wordsList: MutableList<String> = mutableListOf()
However, during my debugging process, I see that the value of wordsList is null and not an empty list like []. I tested the code in kotlin playground and it should be []. I attached a screenshot of what android studio is showing me. What am I doing wrong, why am I not seeing the expected behavior?
Here is the gradle file for my project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the gradle file for my app
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.android.unscramble"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// LiveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
// ViewModel
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
}
Referring to Kotlin docs:
During an instance initialization, the initializer blocks are executed
in the same order as they appear in the class body, interleaved with
the property initializers
So, your breakpoint is probably hit from the upper init { } block when wordsList is not initialized yet. You may choose to initialize your variable before calling getNextWord() or just move this init { } block down so it is executed when all your properties are already initialized.

Android Studio and google play services

I'm getting really frustrated with this. I've managed to make the google play services available in Android Studio but now I can't instantiate an AdView class. I can import import com.google.android.gms.ads.*; no errors there, it just says Unused import but when I try to create an AdView class I get a cannot find symbol error. It also doesn't find com.google.android.gms.ads.AdView or any other class inside that package for that matter.
I tried cleaning/re-building/restarting the IDE but nothing worked so far.
Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/libGoogleAnalyticsServices.jar')
}
Fixed
See this

Categories

Resources