Android Studio报错‘Package name doesnt match regex’,包名合规性问题求助
Hey there, let's break down why you're hitting that "Package name doesn't match regex" error and how to fix it quickly!
问题根源
The core issue here is the uppercase "Utils" in your package name com.mondelicious.yuomi.Utils. Android (and Java/Kotlin) enforces strict rules for package naming, and uppercase letters are not allowed.
官方包名规则回顾
Android requires package names to follow these conventions:
- All characters must be lowercase letters (a-z), digits (0-9), underscores (
_), or dots (.) - Cannot start with a digit or underscore
- Should follow the reverse-domain format (e.g.,
com.yourcompany.appname)
具体修复步骤
Rename the package to use lowercase
ChangeUtilstoutils, so your full package name becomescom.mondelicious.yuomi.utils.Use Android Studio's Refactor tool to update references safely
- Right-click the
Utilspackage folder in your project structure - Select
Refactor > Rename - Choose
Rename Packagefrom the popup options - Enter the new lowercase name
utilsand clickRefactor - Android Studio will automatically update all related files: your manifest, class declarations, import statements, etc.
- Right-click the
Verify key files are updated
- Check your
AndroidManifest.xmlto ensure thepackageattribute matches the new lowercase name:<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mondelicious.yuomi.utils"> - Open any Kotlin/Java class in the package and confirm the top package declaration is:
(or the equivalent for Java)package com.mondelicious.yuomi.utils
- Check your
额外提醒
Avoid manually editing package names across files—this is error-prone and can leave hidden references broken. The refactor tool is designed to handle all these changes in one go.
内容的提问来源于stack exchange,提问作者Marcus Mondel

