Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
Integrating uber-apk-signer
Browse files Browse the repository at this point in the history
  • Loading branch information
Surendrajat committed Mar 6, 2018
1 parent 798ef0b commit 801ad97
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 135 deletions.
6 changes: 2 additions & 4 deletions apkstudio.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ HEADERS += \
include/flickcharm.h \
include/ide.h \
include/installrunnable.h \
include/jarsigner.h \
include/java.h \
include/macros.h \
include/menubar.h \
Expand All @@ -43,7 +42,7 @@ HEADERS += \
include/toolbar.h \
include/viewer.h \
include/widgetbar.h \
include/zipalign.h
include/uberapksigner.h

OTHER_FILES += \
.gitignore \
Expand Down Expand Up @@ -88,7 +87,6 @@ SOURCES += \
src/flickcharm.cpp \
src/ide.cpp \
src/installrunnable.cpp \
src/jarsigner.cpp \
src/java.cpp \
src/main.cpp \
src/menubar.cpp \
Expand All @@ -109,7 +107,7 @@ SOURCES += \
src/toolbar.cpp \
src/viewer.cpp \
src/widgetbar.cpp \
src/zipalign.cpp
src/uberapksigner.cpp

TARGET = apkstudio

Expand Down
1 change: 1 addition & 0 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define REGEX_LF "[\\r\\n]"
#define REGEX_ADB_VERSION "^.*(\\d+)\\.(\\d+)\\.(\\d+)$"
#define REGEX_APKTOOL_VERSION "^(\\d+)\\.(\\d+)\\.(\\d+)$"
#define REGEX_UBERAPKTOOL_VERSION "^.*(\\d+)\\.(\\d+)\\.(\\d+)$"
#define REGEX_JAVA_VERSION "^.*\"(\\d+)\\.(\\d+)\\.(\\d+)_(\\d+)\"$"
#define REGEX_THEME_STYLE "\\b([a-z]+)\\:\\s*([0-9a-z#]+)\\b"
#define REGEX_WHITESPACE "\\s+"
Expand Down
22 changes: 0 additions & 22 deletions include/jarsigner.h

This file was deleted.

31 changes: 31 additions & 0 deletions include/uberapksigner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef UBERAPKSIGNER_H
#define UBERAPKSIGNER_H

#include <QStringList>
#include "macros.h"
#include "java.h"

APP_NAMESPACE_START

class UberApkSigner : public Java
{
private:
QString _jar;
static UberApkSigner *_self;
private:
explicit UberApkSigner(QObject *parent = 0);
public:
// Result build(const QString &project, const QString &apk);
// Result decode(const QString &apk, const QString &project, const QString &framework, const bool sources, const bool resources);
Result sign(const QString &src, const QString &keystore, const QString &keystorePass, const QString &key, const QString &keyPass = QString());
Result signDebug(const QString &src);
inline Result exec(const QString &arg) { return exec(QStringList(arg)); }
Result exec(const QStringList &args = QStringList());
static UberApkSigner *get();
QString getVersion();
};

APP_NAMESPACE_END

#endif // UBERAPKSIGNER_H

22 changes: 0 additions & 22 deletions include/zipalign.h

This file was deleted.

4 changes: 4 additions & 0 deletions res/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@
<source>version_apktool</source>
<translation>APK Tool: %1</translation>
</message>
<message>
<source>version_uberapksigner</source>
<translation>APK Signer: %1</translation>
</message>
<message>
<source>version_java</source>
<translation>Java: %1</translation>
Expand Down
10 changes: 4 additions & 6 deletions src/consoledock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include "include/apktool.h"
#include "include/consoledock.h"
#include "include/constants.h"
#include "include/jarsigner.h"
#include "include/uberapksigner.h"
#include "include/qrc.h"
#include "include/zipalign.h"

APP_NAMESPACE_START

Expand Down Expand Up @@ -35,12 +34,11 @@ ConsoleDock::ConsoleDock(QWidget *parent)
_connections << connect(Adb::get(), &Process::executing, this, &ConsoleDock::onExecuting);
_connections << connect(ApkTool::get(), &Process::executed, this, &ConsoleDock::onExecuted);
_connections << connect(ApkTool::get(), &Process::executing, this, &ConsoleDock::onExecuting);
_connections << connect(JarSigner::get(), &Process::executed, this, &ConsoleDock::onExecuted);
_connections << connect(JarSigner::get(), &Process::executing, this, &ConsoleDock::onExecuting);
_connections << connect(UberApkSigner::get(), &Process::executed, this, &ConsoleDock::onExecuted);
_connections << connect(UberApkSigner::get(), &Process::executing, this, &ConsoleDock::onExecuting);
_connections << connect(Java::get(), &Process::executed, this, &ConsoleDock::onExecuted);
_connections << connect(Java::get(), &Process::executing, this, &ConsoleDock::onExecuting);
_connections << connect(ZipAlign::get(), &Process::executed, this, &ConsoleDock::onExecuted);
_connections << connect(ZipAlign::get(), &Process::executing, this, &ConsoleDock::onExecuting);

}

void ConsoleDock::onExecuted(const Process::Result &r)
Expand Down
38 changes: 0 additions & 38 deletions src/jarsigner.cpp

This file was deleted.

19 changes: 7 additions & 12 deletions src/signrunnable.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <QFile>
#include "include/jarsigner.h"
#include "include/uberapksigner.h"
#include "include/pathutils.h"
#include "include/signrunnable.h"
#include "include/zipalign.h"

APP_NAMESPACE_START

Expand All @@ -17,18 +16,14 @@ void SignRunnable::run()
{
emit runnableStarted();
QString tmp = PathUtils::temp("signed.apk");
Process::Result r = JarSigner::get()->sign(_src, tmp, _keystore, _keystorePass, _key, _keyPass);
Process::Result r;
if(_keystore.isEmpty())
r = UberApkSigner::get()->signDebug(_src);
else
r = UberApkSigner::get()->sign(_src, _keystore, _keystorePass, _key, _keyPass);
if (r.code == 0)
{
r = ZipAlign::get()->align(tmp, _src);
if (r.code == 0)
{
emit signSuccess(_src);
}
else
{
emit signFailure(_src);
}
emit signSuccess(_src);
QFile::remove(tmp);
}
else
Expand Down
12 changes: 12 additions & 0 deletions src/statusbar.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "include/adb.h"
#include "include/apktool.h"
#include "include/uberapksigner.h"
#include "include/java.h"
#include "include/statusbar.h"
#include "include/qrc.h"
Expand All @@ -11,12 +12,15 @@ StatusBar::StatusBar(QWidget *parent)
{
QLabel *adb;
QLabel *apkTool;
QLabel *uberApkSigner;
QLabel *java;
addPermanentWidget(java = new QLabel(this));
addPermanentWidget(new StatusBarSeparator(this));
addPermanentWidget(adb = new QLabel(this));
addPermanentWidget(new StatusBarSeparator(this));
addPermanentWidget(apkTool = new QLabel(this));
addPermanentWidget(new StatusBarSeparator(this));
addPermanentWidget(uberApkSigner = new QLabel(this));
addPermanentWidget(new QWidget(this), 1);
addPermanentWidget(_message = new QLabel(this));
setContentsMargins(4, 0, 4, 0);
Expand All @@ -38,6 +42,14 @@ StatusBar::StatusBar(QWidget *parent)
{
apkTool->setText(__("version_apktool", "statusbar", "n/a"));
}
if ((v = UberApkSigner::get()->getVersion()).isEmpty() == false)
{
uberApkSigner->setText(__("version_uberapksigner", "statusbar", v));
}
else
{
uberApkSigner->setText(__("version_uberapksigner", "statusbar", "n/a"));
}
if ((v = Java::get()->getVersion()).isEmpty() == false)
{
java->setText(__("version_java", "statusbar", v));
Expand Down
67 changes: 67 additions & 0 deletions src/uberapksigner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "include/uberapksigner.h"
#include "include/constants.h"
#include "include/pathutils.h"
#include "include/textutils.h"

APP_NAMESPACE_START

UberApkSigner* UberApkSigner::_self = NULL;

UberApkSigner::UberApkSigner(QObject *parent)
: Java(parent)
{
_jar = PathUtils::find("uber-apk-signer.jar");
}

Process::Result UberApkSigner::sign(const QString &s, const QString &ks, const QString &ksp, const QString &k, const QString &kp)
{
QStringList args("--debug");
args << "-ks" << ks << "--ksPass" << ksp;
if (!kp.isEmpty())
{
args << "--ksKeyPass" << kp;
}
return exec(args << "-a" << s << "--ksAlias" << k << "--overwrite" << "--allowResign");
}

Process::Result UberApkSigner::signDebug(const QString &s)

This comment has been minimized.

Copy link
@Surendrajat

Surendrajat Mar 7, 2018

Author Owner

If a ketstore isn't provided, uber-apk-tool uses its own debugKeyStore for signing app

{
QStringList args("--debug");
return exec(args << "-a" << s << "--overwrite" << "--allowResign");
}

UberApkSigner *UberApkSigner::get()
{
if (!_self)
{
_self = new UberApkSigner();
}
return _self;
}

Process::Result UberApkSigner::exec(const QStringList &a)
{
return Java::exec(QStringList("-jar") << _jar << a);
}


QString UberApkSigner::getVersion()
{
Process::Result r = exec("-version");
QRegularExpression rgx(REGEX_UBERAPKTOOL_VERSION);
foreach (const QString &l, r.output)
{
QRegularExpressionMatch m = rgx.match(l);
if (m.hasMatch())
{
QString v("%1.%2.%3");
for (int i = 1; i <= 3; i++)
{ v = v.arg(m.captured(i)); }
return v;
}
}
return QString();
}

APP_NAMESPACE_END

31 changes: 0 additions & 31 deletions src/zipalign.cpp

This file was deleted.

1 comment on commit 801ad97

@Surendrajat
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Removed jarsigner and zipalign class files
  • Added class for uber-apk-signer
  • Added uber-apk-signer version in status bar

Please sign in to comment.