罗路遥 罗路遥 - 13 days ago 4
Android Question

groovy get attribute from AndroidManifest.xml

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

<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="19" />

<uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name= "android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name="com.emnets.luoly.sample.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>


I would like to get
uses-permission
using groovy.

Maybe like this,

def manifestXml = new XmlParser().parse(Manifest)
manifestXml."uses-permission".each { p ->
println p.attribute("android:name")
}


How to get attribute like
android.permission.WRITE_EXTERNAL_STORAGE

Answer

You can use XmlSlurper

def manifestXml = new XmlSlurper().parse(Manifest)
manifestXml."uses-permission".each { p ->
    println p."@android:name"
}
Comments