`
498320858
  • 浏览: 391760 次
  • 性别: 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/

分享到:
评论

相关推荐

    android apk安装流程及解析

    ### Android APK 安装流程及解析 #### 一、Android 应用安装原理及过程概述 Android APK(Android Package Kit)文件是Android平台上的应用程序安装包格式,包含了应用程序的所有资源和代码。Android APK的安装...

    Android Apk包解析SDK

    Android Apk包解析SDK是一种工具或库,它允许开发者深入理解Apk的内容,提取关键信息,如包名、应用名称、图标等。此SDK特别强调对vector XML格式图标的处理,能够将它们转换为SVG,然后进一步转化为PNG格式,以适应...

    Android apk应用包名获取工具,以及源码

    1. `PackageManager`的使用:在Java代码中,通过`PackageManager`的`getPackageInfo()`方法,传入待查询的APK路径,获取`PackageInfo`对象,其中包含了包名信息。 2. 文件I/O操作:读取APK文件,通常需要处理文件...

    Android APK安装脚本.rar

    当用户下载一个APK并安装时,系统会解析这些内容并将其安装到设备的指定目录。 2. **超级终端**: 超级终端(或称为adb shell)是一种通过ADB(Android Debug Bridge)连接到Android设备的命令行工具。它允许...

    易语言apk查看器源码分享 [超级强大]安卓apk包名和类名查看器 专业查看APK的工具 apk包名查看

    通过研究源码,我们可以了解到如何解析APK文件的结构,获取到包名和类名等关键信息。这涵盖了Android的APK格式解析、资源提取、Dex文件处理等方面的知识。 APK文件本质上是ZIP压缩包,包含了一系列的文件,如`...

    androidapk问题大全解析.pdf

    《Android APK问题大全解析》 Android APK文件是Android应用程序的打包格式,它是Android开发者将编写好的Java代码编译、打包并签名后的产物。这个PDF文件很可能是针对Android开发者或者对Android应用安装、调试有...

    android 安装本地apk

    此外,Android的安装流程包括解压APK、验证签名、解析AndroidManifest.xml以确定应用信息、复制文件到系统目录、安装服务等步骤。安装过程中可能会遇到各种问题,如权限冲突、签名错误、存储空间不足等,需要开发者...

    java实现解析APK

    // 解析包名和版本信息 System.out.println(line); } // 其他解析逻辑... } reader.close(); process.waitFor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` 这...

    apk.rar_.apk_android_android apk_apk

    Android APK文件的工作原理是,当用户下载并安装APK文件时,Android系统会解析该文件,提取出所有必要的组件,并将其安装到设备的指定位置。安装过程中,系统会检查APK的权限请求,如果用户同意,APK就能运行。APK...

    APK包名查看器(APK信息查看器)

    标题中的“APK包名查看器”是一款专用于查看Android应用程序(APK)包名的工具,它允许用户在电脑上无需安装额外的管理软件就能获取APK的相关信息。描述中提到,用户通常可能需要这样的工具来快速查看APK的包名,而...

    PHP 读取 Android APK XML文件,无需JDK

    此外,如果你需要批量处理多个APK文件,可以将上述过程封装成一个函数,接收APK文件路径和XML文件名作为参数,然后在循环中调用该函数。这样可以提高代码的复用性和效率。 总结来说,通过PHP的ZipArchive类,我们...

    androidapk问题大全解析参照.pdf

    【Android APK 安装与管理详解】 Android APK 文件是Android应用程序的打包格式,相当于iOS的ipa文件。在Android开发环境中,通常使用Eclipse或Android Studio等集成开发环境(IDE)来构建和生成APK。Eclipse工程的...

    解析apk的jar包

    "解析apk的jar包"就是这样一个工具,它可以帮助我们提取和查看APK中的重要信息,比如版本号、版本名以及包名等。 首先,我们要了解APK的结构。一个标准的APK文件实际上是一个ZIP格式的压缩包,里面包含了DEX...

    获取apk包名,版本号等信息的jar包

    在Android开发过程中,有时我们需要获取APK包的相关信息,如包名、版本代码(versionCode)、版本名称(versionName)等。这些信息对于版本管理和应用更新检查至关重要。本篇文章将详细解析如何使用Java来获取未安装...

    Java解析apk包

    在Android开发中,APK包是应用程序的二进制文件,包含了应用的代码、资源、配置等所有必要的组件。Java解析APK包是一项常见的技术,主要用于逆向工程、安全分析或者自动化工具的实现。当我们遇到Java解析APK时桌面...

    Android之APK打包安装过程.zip_android 打包_run

    - **解析APK**:当用户下载APK并尝试安装时,Android系统会解析APK文件,检查其权限、签名和版本信息。 - **验证签名**:系统使用公钥验证APK的数字签名,确保未被篡改。 - **提取文件**:APK内容被解压到设备的特定...

    解析APK的包名和主Activity

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

    PHP解析APK包获取所有信息

    本文将深入探讨如何利用PHP解析APK包,获取其中包含的各种元数据,如应用名称、版本信息、图标名以及包名等关键信息。 首先,我们需要了解APK文件的本质。APK是Android系统中应用的安装包格式,它实际上是一个ZIP...

    c#实现解析apk、ipa包

    在IT行业中,解析APK和IPA包是一项常见的任务,尤其对于开发者来说,了解包的内部结构和内容至关重要。本文将详细介绍如何使用C#语言来实现这一功能,主要针对标题和描述中的知识点进行深入探讨。 首先,我们要理解...

Global site tag (gtag.js) - Google Analytics