资源简介
Android R.java类生成工具,可以用来生成R.java类的Python脚本,基于Python2.7版本。
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import codecs
import ConfigParser
import xml.dom.minidom
import re
# 获取配置文件解释器
def getConfigParser() :
configFile = os.path.join(os.path.dirname(__file__) ‘config.ini‘)
if os.path.exists(configFile):
parser = ConfigParser.ConfigParser()
parser.read(configFile)
return parser
# 判断是否是资源目录
def isResDir(projectOrResDir):
manifestFile = os.path.join(projectOrResDir ‘AndroidManifest.xml‘)
gradleFile = os.path.join(projectOrResDir ‘build.gradle‘)
resTypes = (‘drawable‘ ‘layout‘ ‘anim‘ ‘animator‘ ‘values‘)
if not os.path.exists(manifestFile) and not os.path.exists(gradleFile):
(_ dirNames fileNames) = os.walk(projectOrResDir).next()
if len(fileNames) == 0:
for folder in dirNames:
for resType in resTypes:
if folder.startswith(resType):
return True
return False
# 判断是否是Eclipse的工程
def isEclipseProject(projectDir):
manifestFile = os.path.join(projectDir ‘AndroidManifest.xml‘)
return os.path.exists(manifestFile)
# 判断是否是AndroidStudio的工程
def isAndroidStudioProject(projectDir):
manifestFile = os.path.join(projectDir ‘AndroidManifest.xml‘)
gradleFile = os.path.join(projectDir ‘build.gradle‘)
if os.path.exists(manifestFile):
return False
else:
return os.path.exists(gradleFile)
def getDefaultAaptFile(sdkdir):
toolsPath = os.path.join(sdkdir ‘build-tools‘)
if os.path.exists(toolsPath):
_ dirNames _ = os.walk(toolsPath).next()
if len(dirNames) != 0:
verPath = os.path.join(toolsPath dirNames[0])
aaptPath = os.path.join(verPath ‘aapt.exe‘)
print ‘aapt is at ‘ + aaptPath
return aaptPath
def getDefaultAndroidjarFile(sdkdir):
platformPath = os.path.join(sdkdir ‘platforms‘)
if os.path.exists(platformPath):
_ dirNames _ = os.walk(platformPath).next()
if len(dirNames) != 0:
verPath = os.path.join(platformPath dirNames[0])
androidjarPath = os.path.join(verPath ‘android.jar‘)
print ‘android.jar is at ‘ + androidjarPath
return androidjarPath
def getAaptFile(isEclipse projectDir sdkdir):
# 对Eclipse工程,在工程目录的project.properties文件中配置有编译时使用的目标版本
# 如:target=android-23
if isEclipse:
settingFile = os.path.join(projectDir ‘project.properties‘)
if os.path.exists(settingFile):
regex = re.compile(r‘^\s*target\s*=\s*android-(\d+)‘)
fp = open(settingFile ‘r‘)
lines = fp.readlines()
for line in lines:
ret = regex.search(line)
if ret:
buildVersion = ret.group(1)
toolsPath = os.path.join(sdkdir ‘build-tools‘)
if os.path.exists(toolsPath):
评论
共有 条评论