Skip to content

Commit

Permalink
chore: reduce android binary size
Browse files Browse the repository at this point in the history
  • Loading branch information
cawfree committed Dec 29, 2022
1 parent d4c51e7 commit 1ee0149
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
20 changes: 13 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,34 @@ export default function App() {
const four_bytes = `/ipfs/bafybeicsj2jntw5nf4ld23czky3ydhpivphgivcgcxegzbqpdxrhbgfu3y/4bytes`;
const bytecode = `${four_bytes}/f78d1c6a`;

const [{ data: helloWorlds }] = await Promise.all([
axios({
url: `${uri}/cat?arg=QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx`,
method: 'post',
}),
]);

console.warn(helloWorlds);

const [
{ data: helloWorlds },
{
data: { Path: resolvedHash },
},
] = await Promise.all([
axios({
url: `${uri}/cat?arg=QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx`,
method: 'post',
}),
axios({
url: `${uri}/resolve?arg=${bytecode}`,
url: `${uri}/resolve?arg=${bytecode}&recursive=true&dht-timeout=0`,
method: 'post',
}),
]);

console.warn(resolvedHash);

const { data: signature } = await axios({
url: `${uri}/cat?arg=${resolvedHash}`,
method: 'post',
});

console.warn(helloWorlds, signature);
console.warn(signature);

await stop();
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"android/*",
"android/src/libs/*",
"android/src/main/java/*",
"!android/.idea",
"!android/build",
"!android/gradle",
"!android/.gradle",
"!android/gradlew",
"!android/gradlew.bat",
"!android/local.properties",
Expand Down
23 changes: 23 additions & 0 deletions scripts/gomobileup.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ const aar_to = path.resolve(libs, 'core.aar');

fs.copySync(aar, aar_to);

child_process.execSync(`unzip core.aar`, { stdio, cwd: libs });

fs.removeSync(aar_to, { recursive: true });

// HACK: Remove some of the supported platforms from the .aar to reduce the binary size:
const platforms_to_remove = ['x86', 'x86_64'];

platforms_to_remove
.map((e) => path.resolve(libs, 'jni', e))
.forEach((e) => fs.removeSync(e, { recursive: true }));

const filesToZip = fs.readdirSync(libs);

child_process.execSync(
`zip -r9 core.aar ${filesToZip.join(' ')}`,
//`zip -r core.aar ${filesToZip.join(' ')}`,
{ stdio, cwd: libs }
);

filesToZip.forEach((file) =>
fs.removeSync(path.resolve(libs, file), { recursive: true })
);

const bridge = path.resolve(
gomobile_ipfs,
'android',
Expand Down

0 comments on commit 1ee0149

Please sign in to comment.