`
498320858
  • 浏览: 386384 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

android apk 安装路径 包名解析 覆盖安装等问题

阅读更多

 

Android package name

16thDec. × ’09

There are two independent notions of “package” in Android. One is the usual Java package, which is how the Java classes are organized inside your project. The other is the Application package, which is an unique application identifier used by Android to manage the installed applications. The two package names are completely independent and serve different purposes.

Java package

The Java package organizes the classes inside the application. Usually you have multiple Java packages in an application. You may put your own classes in a package that’s specific to your app (e.g. “com.domain.myapp”) and you keep the library classes that your project uses in their predefined Java package (e.g. “org.apache.lucene”). The Java packages in your app are mostly the internal business of your app and have little visibility outside of the application — they are visible only for the classes that are exposed to the system such as Activities, Views, Services etc you implement and specify in your app’s AndroidManifest.

What’s more, the Java packages of an application are local to that app. There can be multiple independent applications that implement the same class in the same package, and there is no conflict whatsoever.

The Java package is always scoped inside the application. Two Java packages with the same name (e.g. “org.apache.lucene”) located in different apps are in fact different packages and there is no identity or relation between them. This allows applications to use well-known libraries (such as our lucene example) without any possible interference with other apps that may use the same package/classes (or different versions of). The drawback is that there is duplicated code if many apps use the same classes over again (there is no reuse in-between the apps based on the Java package name).

The observation that on Android the Java package is local to the application means that we don’t have to worry about package name conflicts with other applications. Avoiding package name conflicts with unforeseen third-party apps was the main reason for the Java package name format “com.mydomain.myapp”, i.e. prefixing with your domain name avoids conflict — but there’s no possible conflict on Android to avoid.

This leads to the possibility of using liberal Java package names that violate the well-established Java convention. For example if your app is called “Calculator”, you may place classes in the Java package “calculator” instead of “com.mydomain.calculator” — how cool is that? Of course, that fact that you can does not mean that you should, and respecting the established convention is a good thing even though it’s not required on Android.

Application package

The Application package declared in the AndroidManifest.xml is specific to Android and is an identifier of the application. This identifier is unique among all the apps installed on the phone at a given moment — there can’t be two apps with the same Application package installed at the same time.

The Application package is also unique on the Android Market — there can’t be two apps with the same Application package on the Market.

On the other hand it is possible for two independent developers to create two different apps with the same Application package. Of course not both apps can be hosted on the Market — the Market would reject the second one due to the “unique App package name across Market” rule.

So conflict over the Application package with unforeseen third-party apps is possible, and that’s why it is recommended to use the Java package name convention (“com.mydomain.myapp”) for the Application package name as it avoids conflict.

Some developers chose to disregard the guideline “com.mydomain.myapp” and use fancy Application package names, e.g. “marcone.toddlerlock” for the ToddlerLock application — this liberal use is likely not recommended but certainly possible.

If you use unorthodox Application package names please be sure to make them very specific in order to minimize the chance of conflict (in the previous example, the “marcone.” prefix is specific to the developer and has little chance of conflict (hint: it’s derived from the developer’s name)).

Identifying Java classes across an Android system

To identify a Java class across an Android system (a class that can be part of any application) you have to specify both the Application package and the Java package and class name. It’s like you first specify the application with the App package, and then you specify the class inside the application with the Java package and class name. This is used for example when constructing an Intent to a specific class.

Because often the Application package is the same as the Java package (i.e. the same string), it appears as if you have to specify the package name twice! This can be a bit confusing in the beginning, but it becomes clear why both package names are needed as soon as you understand the difference between the Application package and Java package.

When specifying activity names in the AndroidManifest.xml you need to indicate the Java package and class name (e.g. “com.mydomain.myapp.MyActivity”). Android also allows the short-hand form “.MyActivity”, which indicates that the Java package for the given activity class is the same as the Application package, which is often the case. Of course if your app uses different Application package and Java package, you can’t use the short-hand form and need to always use the full Java package in the manifest.

This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

<!-- .entry-utility --><!-- .post -->

6 Comments

  1. Pierre
    Posted 2010-02-05 at 09:04 | Permalink

    That is clearly and simply explained. Thank you very much for this useful entry !

  2. Posted 2010-08-07 at 13:14 | Permalink

    This is a clearly articulated description of the Android package names. I appreciate the post and it clears up a lot of questions that I had.

  3. Posted 2010-08-12 at 23:58 | Permalink

    So, that’s it, very well explained. The two packages has a huge difference, and nothing to compare with them since they manifest in a different way as well. Hands down on you, i have nothing to ask anymore.

  4. Posted 2010-08-23 at 18:54 | Permalink

    Thank you. Nice explanation, very useful !

  5. Diaz
    Posted 2010-10-06 at 13:07 | Permalink

    I’m just starting android development and when I started my new android project , stopped after seeing the “package name” to google what should I worry about when naming my packages and what not. At first, I thought it was the same as Java packages. phew, good thing I’ve found this post. Saved me alot of headach. Thank you so much Mihai

  6. Posted 2010-10-13 at 13:25 | Permalink

    There is some overlap between the two types of packages. The generated R.java is created in a Java package that has the same name as the Android package. This causes problems when trying to use Android maven tools to generate two separate Android packages from a common base.

<!-- #comments-list .comments -->

One Trackback

  1. [...] Next up is to create and configure an Android project.  The application name is very important in creating an Android application.  The application name must be unique across the entire Google market as explained here. [...]

 

 

 

 

转载自:http://blog.javia.org/android-package-name/

分享到:
评论

相关推荐

    解析APK的包名和主Activity

    程序自动开启其他APK 需要知道 包名和主Activity Android SDK platform-tools目录下有个aapt.exe 可以帮忙解析其他APK的包名和主Activity 需要先确定环境变量中的配置可以正常使用aapt.exe

    apkutil(解析apk安装包的工具 )

    apkUtil是一个用来解析apk安装包的工具,通过它可以获取一个安装包的图标、程序名、所需android平台,权限等信息,并将其转换为java对象。 该工具依赖于aapt工具,目前仅支持在windows平台上运行。 程序在运行时,...

    apk的结构解析

    apk的结构解析,主要包括目录及各文件、文件夹的作用和内容

    soot-android-scala:在 Scala 中对 android apk 运行烟尘分析

    在 Scala 中对 android apk 运行烟尘分析 为您的平台获取 sbt(所有 Scalas 都是您的) 然后在示例 apk 上运行此项目: $ git clone $ cd soot-android-scala $ sbt "run platforms 1.apk" 平台/目录是占位符...

    新版Android开发教程.rar

    这一联盟将会支持 Google 发布的 Android 手机操作系统或者应用软件,共同开发名为 Android 的 开 放源代码的移动系统。开放手机联盟包括手机制造商、手机芯片厂商和移动运营商几类。目前,联盟成员 数 量已经达到了...

    Android静默安装常用工具类

    Android包相关工具类,可用于(root)安装应用、(root)卸载应用、判断是否系统应用等,如: install(Context, String) 安装应用,如果是系统应用或已经root,则静默安装,否则一般安装 uninstall(Context, String) ...

    Android入门

    Android移动开发: Android 开发环境搭建 第一个项目—HelloAndroid Android项目目录结构 Android应用解析 Android生命周期 Widget开发 Android中的显示单位 DDMS的简介与使用 apk的安装与卸载

    apk 反编译

    2) 输入 apktool d "xxx.apk的全路径" "反编译后的路径",回车 3) 进入反编译后的目录即可看到东东 2.源代码反编译 工具:1) dex2jar-0.0.7-SNAPSHOT 2) jd-gui-0.3.3.windows 步骤:1) 将xxx.apk改名为xxx.zip...

    2010年谢彦的android笔记

    3.2.12 解析apk包内容 69 3.3 Java对C库的调用 70 3.3.1 android中使用JNI 70 3.3.2 安装使用NDK 72 3.3.3 在源码中将库打进apk 73 3.3.4 简单的C库调试方法 75 3.4 典型应用 76 3.4.1 语音合成 76 3.4.2 语音识别...

    adb1.0.26包含fastboot.exe

    又如想给 10.129.164.6:5555 这个设备安装应用(这种形式的 serialNumber 格式为 &lt;IP&gt;:,一般为无线连接的设备或 Genymotion 等第三方 Android 模拟器): adb -s 10.129.164.6:5555 install test.apk 遇到多设备/...

    Android开发与应用——张荣,原书配套课件

    这是Android开发与应用,原书配套的课件,作者张荣,目录如下。 第1章 Android简介 1.1 手机操作系统 1.2 Android起源 1.3 Android特征 1.4 Android体系结构 1.4.1 应用层 1.4.2 应用框架层 1.4.3 ...

    超级授权管理:SuperSU Pro(Android)

    包名:eu.chainfire.supersu SuperSU(超级授权管理)是款功能超强超级用户访问权限管理工具。SuperSU支持已ROOT设备上所有应用的超级用户访问权限的高级管理,在超级用户管理工具的基础上,功能更强,更稳定! ...

    Android 开发入门

    主要介绍了 Android 开发环境搭建 第一个项目—HelloAndroid Android项目目录结构 Android应用解析 Android生命周期 Widget开发 Android中的显示单位 DDMS的简介与使用 apk的安装与卸载

    虹软人脸识别 – Android平台调用动态库时的常见错误解析

    最近我们发现很多用户在接入虹软ArcFace人脸识别SDK时,经常会遇到动态库加载失败的相关问题。...在安装应用时,APK中指定的ABI目录下没有发现指定的动态库,寻找apk中动态库的规则详见 https://developer

    Android快速分析apk工具aapt的使用教程

    aapt即Android Asset Packaging Tool,我们可以在SDK的platform-tools目录下找到该工具。aapt可以查看、 创建、 更新ZIP格式的文档附件(zip, jar, apk)。 也可将资源文件编译成二进制文件,尽管你可能

    基于AndroidStudio的体育新闻类型app项目源码

    项目介绍 本项目实现的是Android平台下的体育新闻类型app,名称叫做腾飞体育。实现的内容主要有进入app前展示应用的logo及名称的...该项目已打包,apk文件在app/release目录下,各位可以将其安装到Android手机上体验

    解析Android资源文件及他们的读取方法详解

    Sam在Android开发中,有两种处理资源文件的方式。其一,是将所有资源文件以及JNI程序放置于一个单独的资源包。使用到他们时,使用文件...此时,用户安装APK后,不用再费力copy资源包。方便发布。这次主要介绍的是第二

    Google Android SDK开发范例大全(第3版) 1/5

    Web Service存取服务:内嵌网页浏览器、Ajax网页特效、手机气象局、网络播放mp3、网络安装apk程序、远程下载手机铃声、XML-RPC移动博客发布器、手机RSS阅读器、地震速报、网页快照等。 完备的Google网络服务:Google...

Global site tag (gtag.js) - Google Analytics