罗路遥
罗路遥

Reputation: 185

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

Upvotes: 1

Views: 889

Answers (2)

lisperl
lisperl

Reputation: 101

Use XmlSlurper get ActivityName

    def manifest = new XmlSlurper().parse(xmlFilePath)
    String pkg = manifest.@package
    manifest.application.activity.each {
        String actName = it.'@android:name'
        if (actName.substring(0, 1).equals('.')) {
            actName = pkg + actName
        }
        println(actName)
    }

Upvotes: 2

user3718614
user3718614

Reputation: 530

You can use XmlSlurper

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

Upvotes: 4

Related Questions