技术文档: https://docs.tradplusad.com/docs/tradplussdk_android_doc_v6/download
容易出错 新人入手也比较麻烦
在Traplus接入开头处 加上
/// TradPlus Start //
在Tradplus接入结尾处 加上
/// TradPlus End //
修改配置文件 ads 需要接入的广告渠道配置
仅需要在第一次和每次运营更换广告渠道的时候 配置一次
一般情况下这个版本号是Tradplus官方的人来告诉你这是哪个版本号 改一次就好了
主运行脚本
#默认服务端口
import requests
import time
import implant
import downloadUnityPlugins
api = 'https://www.geek7.top:8000/api'
adsChannel = ['UnityAds']
region = '2' # 1: 中国 2: 其它地区
adsChannel.clear()
sdkversionList = []
versionstr = ""
def log( msg ):
print( msg )
def InitChannel():
adsChannel.clear()
with open('./bin/ads','r') as fp:
for line in fp.readlines():
adsChannel.append(line.replace('\n',''))
def Run( sdk_version = "10.2.0.1",overrid = True ):
global versionstr
InitChannel()
data = {
'token' : time.time(),
'pipe':'tradplussdk',
'code':829,
'adchannels':','.join(adsChannel),
'version':sdk_version,
'region' : region
}
res = requests.get(api,data)
j = res.json()
if 'version' not in j:
log('erro: not foud version property in result.data')
return
if 'data' not in j:
log('erro: data not in depends')
return
appGradleCode = j['data']
if None == appGradleCode:
log('GetDependencies fail')
else:
print('input you "Assets\\Plugins\\Android" full path')
print('example: D:\\Git\\2dtoilet\\2dtoilet-client\\Assets\\Plugins')
print('Or you can try the Android folder to this window.')
print('current tradplus version list:')
v = j['version']
versionstr = '|'.join(v.split(',')[0:10])
print(versionstr)
if not overrid:
sdkversionList.clear()
sdkversionList.extend(v.split(','))
return
srcpath = input('input proj:\n')
realpath = srcpath.replace('\\','/')
implant.Run(realpath,appGradleCode)
u3dzip = j['u3dzip']
print(f'download unity plugin: {u3dzip}')
downloadUnityPlugins.dowanlodZip(u3dzip,'./tradplus_unity_plugin_zips')
if __name__ == "__main__":
log('begin.')
Run( "10.2.0.1", False )
version = ""
while True:
version = input('input you tradplus version: ')
print(f'pulling the current version dependency of Tradplus: {version}')
if version in sdkversionList:
break
else:
print(f'current version fail. :{version}')
print(versionstr)
Run( version )
input('end.')
自动化植入mainTemplate.gradle脚本
import os
def Run( projpath, dependsContent ):
print(f'project path: {projpath}')
print(f'depend content: {dependsContent}')
if not projpath.endswith('mainTemplate.gradle'):
projpath = os.path.join(projpath,'mainTemplate.gradle')
filterstr = ''
dependlines = dependsContent.splitlines()
tradplusContent = False
admob = False
admob_bidding = False
admob_bidding_str = "22.1.0.0"
with open('./bin/ADMOB BIDDING','r') as fp:
lines = fp.readlines()
if len(lines) > 0:
admob_bidding_str = lines[0]
print(f"ADMOB BIDDING : {admob_bidding_str}")
for l in dependlines:
if l.startswith('dependencies {'):
tradplusContent = True
elif l.startswith('android {'):
filterstr = filterstr[0:-2]
break
elif tradplusContent:
real = l.replace('\"','\'')
if admob:
admob = False
si = real.find('\'')
ei = real.find('\'',si+1)
com = real[si:ei+1]
_import = ''' implementation(%s) {
exclude module: "play-services-measurement-sdk-api"
}\n'''%(com)
filterstr += _import
admob_bidding = True
continue
if admob_bidding and '// ' in real:
_import = ''' //ADMOB BIDDING
implementation ('com.applovin.mediation:google-adapter:%s'){
exclude module: "play-services-measurement-sdk-api"
}\n'''%(admob_bidding_str)
filterstr += _import
admob_bidding = False
if '// Admob' in real:
admob = True
filterstr += f'{real}\n'
output = ''
with open(projpath,'r',encoding='UTF-8') as fp:
begin_write = False
lines = fp.readlines()
for line in lines:
if line.startswith(' /// TradPlus Start //'):
output += ' /// TradPlus Start //\n'
output += filterstr
begin_write = True
elif line.startswith(' /// TradPlus End //'):
output += ' /// TradPlus End //\n'
begin_write = False
elif not begin_write:
output += line
if len(output) != 0 and output != '':
print('Under implantation.')
with open(projpath,'w',encoding='UTF-8') as fp:
fp.write(output)
print('Complete implantation.')
else:
print('got a little problem')
下载unity最新插件脚本
import requests
import zipfile
import tempfile
import os
def get_data( url ):
response = requests.get(url)
return url, response.content
def dowanlodZip( url , dest = "./zip"):
url, data = get_data( url ) # data为byte字节
_tmp_file = tempfile.TemporaryFile() # 创建临时文件
print(_tmp_file)
_tmp_file.write(data) # byte字节数据写入临时文件
# _tmp_file.seek(0)
print(f'extract to: {os.path.join(os.getcwd(),dest)}')
zf = zipfile.ZipFile(_tmp_file, mode='r')
for names in zf.namelist():
f = zf.extract(names, dest) # 解压到zip目录文件下
print(f)
zf.close()
print('extract completed')