How to find out which Android API APK was created against

When an APK is created with a given API level, is there a way to find out which API level was used to compile only with the APK file?

MinSdkVersion does not necessarily correspond to the API level used to compile the project, it’s just a note for the Android installer to block the application, if minSdkVersion> the current version

+5
source share
5 answers
BuildConfig.VERSION_CODE; 

and

 getPackageManager().getPackageInfo(...). 

will give us:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... android:versionCode="1" android:versionName="..."> 

versionCode, 1 in this example.

The API level used to compile .apk could not find a way to consult it at run time, but if you use gradle , you can check it out:

 android { compileSdkVersion 22 buildToolsVersion "22.0.1" ... } 

if you use .iml configured using the graphical interfaces of the IntelliJ project:

 <component name="NewModuleRootManager" inherit-compiler-output="true"> ... <orderEntry type="inheritedJdk" /> ... </component> 

project.properties

 # This file is automatically generated by IntelliJ IDEA # Project target. target=Google Inc.:Google APIs:22 

but since build.gradle , project.iml and project.properties do not ship with .apk, I cannot think of a way to get the compileSdkVersion command at runtime or unzip .apk

+2
source

This is another way to get the targetSdkVersion and versionCode my application:

 try { PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode; int targetSdkVersion = packageInfo.applicationInfo.targetSdkVersion; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, e.getMessage()); } 

using Android Studio , the values ​​are defined in the build.gradle file

  defaultConfig { applicationId "com.tuna.hello.androidstudioapplication" minSdkVersion 9 targetSdkVersion 22 versionCode 12 versionName "1.0" } 
+2
source

All that you could get should be in ApplicationInfo, which you get from PackageManager, so you should get ApplicationInfo, and then see what you can extract from it, that is:

 getPackageManager().getPackageInfo(...).targetSdkVersion 

Link: http://developer.android.com/reference/android/content/pm/ApplicationInfo.html

Go to the "Fields" section of the link. Look at the "sourceDir" field.

I hope this helps you, and please vote for everything that helped / missed you.

Sincerely.

+1
source

Try the following:

 android.os.Build.VERSION.SDK_INT 
0
source

How to find out which Android application your application is running in:

 int myAPI = Build.VERSION.SDK_INT; 

How to find out VersionCode APK version:

 String versionCode = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionName; 

Note: ctx is the application context.

But more specifically, change the extension of your APK file to .zip and extract Manifest.xml , after which you can see versionCode , minSdkVersion , targetSdkVersion , etc.

0
source

All Articles