国家/地区代码选取器问题:找不到库



我正在尝试构建一个应用程序,在该应用程序中,我使用";联系人号码";因此,它需要使用"国家代码选择器"库。即使在我的模块(build.gradle(文件中声明了国家代码选择器库,我在XML文件中使用它时仍然会遇到这个错误。

Class referenced in the layout file, com.hbb20.CountryCodePicker, was not found in the project or the libraries

XML文件

<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
app:ccp_autoDetectCountry="true"
app:ccp_showNameCode="false"
tools:ccp_contentColor="#fcfdfd"
tools:ccp_textSize="20dp" />

build.gradle文件

plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.whatsappclone"
minSdkVersion 19
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'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.hbb20:ccp:X.Y.Z'
}

像这样放入依赖项->实现"com.hbb20:ccp:2.5.0">

您需要在粘贴的依赖项中输入有效版本implementation 'com.hbb20:ccp:X.Y.Z'
版本号不是X.Y.Z,而是2.4.2
所以试试这个implementation 'com.hbb20:ccp:2.4.2'并同步你的gradle文件
如果有效,请告诉我
您可以参考https://github.com/hbb20/CountryCodePickerProject#how-添加到您的项目

我想你忘了这一点添加项目等级

repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}

将依赖项设置为正确的格式。

在gradle文件中,您使用了实现"com.hbb20:ccp:X.Y.Z",其中X、Y、Z表示库版本。

所以放上最新版本或任何支持的版本。

最新更新