当前位置: 首页 > news >正文

Android Studio编译旧的app代码错误及解决方法

‘android.injected.build.density’ is deprecated.

The option ‘android.injected.build.density’ is deprecated.
It was removed in version 8.0 of the Android Gradle plugin.
Density property injection from Android Studio has been removed.

解决

app/build.gradle
apply plugin: ‘com.android.application’
改成
plugins {
id ‘com.android.application’
}

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ‘:app’.

Failed to notify project evaluation listener.
‘org.gradle.api.file.RegularFileProperty org.gradle.api.file.ProjectLayout.fileProperty(org.gradle.api.provider.Provider)’

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 46s

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings

解决

build.gradle
buildscript {
apply from: ‘dependencies.gradle’
dependencies {
classpath gradlePlugins.android
}
}
改成
dependencies {
classpath ‘com.android.tools.build:gradle:7.1.1’
}

Failed to apply plugin ‘com.android.internal.version-check’.

Failed to apply plugin ‘com.android.internal.version-check’. Minimum supported Gradle version is 7.2. Current version is 6.8. If using the gradle wrapper, try editing the distributionUrl in xx/gradle/wrapper/gradle-wrapper.properties to gradle-7.2-all.zip

解决

删除.idea .gradle
点击Android studio中的 File->Invalidate cache删除cache

如果不存在gradle/wrapper/gradle-wrapper.properties
则创建此目录mkdir -p gradle/wrapper
并新建 gradle/wrapper/gradle-wrapper.properties
如果存在则直接修改
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.2-all.zip

Could not get unknown property ‘versions’ for extension ‘android’ of type

Could not get unknown property ‘versions’ for extension ‘android’ of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

解决

修改app/build.gradle文件中的compileSdkVersion versions.compileSdk为compileSdkVersion 28

Could not get unknown property ‘libraries’ for object of type

Could not get unknown property ‘libraries’ for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

解决

修改app/build.gradle
这行compile libraries.supportAppCompat
改为
implementation(‘com.android.support:support-v4:23.0.+’)

Could not find method compile() for arguments [directory ‘libs’] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandle

org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method compile() for arguments [directory ‘libs’] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandle

解决

build.gradle中
compile fileTree(include: ['.jar’], dir: ‘libs’)
改为
implementation fileTree(dir: “libs”, include: ["
.jar"])

SDK Build Tools version (28.0.3) is ignored

The specified Android SDK Build Tools version (28.0.3) is ignored, as it is below the minimum supported version (30.0.3) for Android Gradle Plugin 7.1.1.
Android SDK Build Tools 30.0.3 will be used.

解决

app/build.gradle中
buildToolsVersion ‘28.0.3’
改为
buildToolsVersion “30.0.3”

错误: 程序包android.support.v7.app不存在

程序包android.support.v7.app不存在 import android.support.v7.app.NotificationCompat;
错误: 程序包android.support.v4.app.NotificationCompat不存在

解决

app/build.gradle的dependencies中添加
implementation(‘com.android.support:support-v4:23.0.+’)

找不到符号 ContextCompat.startForegroundService

找不到符号
ContextCompat.startForegroundService(context,todayStepIntent);
符号: 方法 startForegroundService(Context,Intent)
位置: 类 ContextCompat

解决

代码ContextCompat.startForegroundService(context,todayStepIntent);改成
context.startForegroundService(todayStepIntent);

AAPT: error: style attribute 'attr/colorPrimary

ERROR:TodayStepCounter/app/src/main/res/values/styles.xml:4:5-9:13: AAPT: error: style attribute ‘attr/colorPrimary (aka com.example.android.todaystepcounter:attr/colorPrimary)’ not found.

解决

app/build.gradle中加
implementation ‘com.android.support:appcompat-v7:26.1.0’
注意如果是比较旧的安卓程序,有些代码比较旧只能用v7:26.1.0,不能用
implementation ‘com.android.support:appcompat-v7:28.0.0’

作者:帅得不敢出门 csdn原创谢绝转载

http://www.lryc.cn/news/209275.html

相关文章:

  • Docker的架构与自制镜像的发布
  • 嵌入式系统中C++ 类的设计和实现分析
  • 【torch高级】一种新型的概率学语言pyro(02/2)
  • Git基本概念与使用
  • Kubernetes数据卷Volume和数据卷分类(emptyDir、nfs、hostPath、ConfigMap)详解
  • 【MATLAB源码-第59期】基于matlab的QPSK,16QAM164QAM等调制方式误码率对比,调制解调函数均是手动实现未调用内置函数。
  • 经典目标检测神经网络 - RCNN、SSD、YOLO
  • mysql存在10亿条数据,如何高效随机返回N条纪录,sql如何写
  • c语言中啥时候用double啥时候用float?
  • vscode 保存 “index.tsx“失败: 权限不足。选择 “以超级用户身份重试“ 以超级用户身份重试。
  • 综合性练习
  • threejs(7)-精通粒子特效
  • 使用了百度OCR,记录一下
  • 5.OsgEarth加载地形
  • 基于回溯搜索算法的无人机航迹规划-附代码
  • 微信小程序云开发笔记-初始化商城小程序
  • vulnhub_DeRPnStiNK靶机渗透测试
  • 网站如何判断请求是来自手机-移动端还是PC-电脑端?如何让网站能适应不同的客户端?
  • sass和 scss的区别?
  • Vuex 动态模块状态管理器
  • 实现分片上传、断点续传、秒传 (JS+NodeJS)(TypeScript)
  • 浅谈安科瑞EMS能源管控平台建设的意义-安科瑞 蒋静
  • 【原创】指针变量作为函数参数要点注意+main函数中值是否改变
  • 售后处置跟踪系统设想
  • python实现ModBusTCP协议的server
  • AndroidStudio编译错误‘android.injected.build.density‘ is deprecated
  • 计网小题题库整理第一轮(面向期末基础)(3)
  • 进程控制(一):进程终止
  • 特殊类设计[下] --- 单例模式
  • 计算机网络-应用层(1)