我正在尝试构建一个应用程序,在该应用程序中我使用“联系电话”实现身份验证,因此它需要使用“国家/地区代码选择器”库。即使在我的模块 (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'
}
答案 0 :(得分:0)
像这样放入你的依赖项 -> implementation 'com.hbb20:ccp:2.5.0'
答案 1 :(得分: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-to-add-to-your-project
答案 2 :(得分:0)
以正确的格式放置依赖项。
在你使用的 gradle 文件中,'com.hbb20:ccp:X.Y.Z' 在这里 X,Y,Z 指的是库版本。
所以放最新版本或任何支持的版本。