migration - AndroidX FrameLayout layout_heightPercent 属性未找到错误
问题描述
尝试将我的 Android 项目从 API 25 升级到 AndroidX ,我在布局中使用以下内容
<FrameLayout
android:id="@+id/frame0"
app:layout_heightPercent="10%"
android:layout_marginTop="50dp"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewFirstPage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_1"
android:layout_gravity="center"
/>
这是 AndroidX 的升级 gradle 文件 - 取自 GitHub Google Samples
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-iid:20.0.2'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'android.arch.work:work-runtime:1.0.1'
现在我在 FrameLayout AAPT 中收到类似 layout_heightPercent 的错误:错误:在 AdMob 横幅中找不到属性 adUnitId
根据文档,我找不到合适的库。一点帮助将非常有用。
解决方案
以下是app gradle文件内容
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.myproject"
minSdkVersion 16
targetSdkVersion 30
versionCode 5
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
useLibrary 'org.apache.http.legacy'
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'com.github.PhilJay:MPAndroidChart:v2.1.6'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:19.2.0'
implementation 'com.google.firebase:firebase-iid:20.2.3'
implementation 'com.google.firebase:firebase-messaging:20.2.3'
// For an optimal experience using FCM, add the Firebase SDK
// for Google Analytics. This is recommended, but not required.
implementation 'com.google.firebase:firebase-analytics:17.4.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
以下是项目gradle
// 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:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
更新后,我们需要重构项目。有时我们需要相应地更改项目中的导入语句。
推荐阅读
- javascript - 如何使用 JavaScript 显示缩略图并在点击时打开模式
- java - 如何从另一个类调用方法?
- jquery - Highcharts - 导出 CSV 包括附加数据
- ruby-on-rails - 在暂存环境中获取请求标头始终为零
- javascript - 如何在 p5.js 中旋转俄罗斯方块?
- php - Multiple connection database with mysqli
- r - 如何在不重新缩放数据的情况下并排绘制带有条形的 2 y 轴图表
- apache-spark - hbase 刷新表上的 Hive
- php - 如何使用 mysql 和 php 计算列值的总和?
- r - 如何使用 geojsonio 包保存 ID?