Skip to content

Commit 615b244

Browse files
Mihail Slavchevfealebenpae
authored andcommitted
update project reference with relative library path
1 parent b40c688 commit 615b244

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lib/services/android-project-service.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class AndroidProjectService implements IPlatformProjectService {
150150
var lines = fs.readFileSync(projProp, { encoding: "utf-8" }).split("\n");
151151
var thiz = this;
152152

153-
lines.forEach(function (elem, idx, arr) {
153+
lines.forEach((elem, idx, arr) => {
154154
var match = elem.match(/android\.library\.reference\.(\d+)=(.*)/);
155155
if (match) {
156156
var libRef: ILibRef = { idx: parseInt(match[1]), path: match[2] };
@@ -174,15 +174,27 @@ class AndroidProjectService implements IPlatformProjectService {
174174
var lines = fs.readFileSync(projProp, { encoding: "utf-8" }).split("\n");
175175
var thiz = this;
176176

177-
lines.forEach(function (elem, idx, arr) {
177+
var maxIdx = 0;
178+
var refs: ILibRef[] = [];
179+
180+
lines.forEach((elem, idx, arr) => {
178181
var match = elem.match(/android\.library\.reference\.(\d+)=(.*)/);
179182
if (match) {
180183
var libRef: ILibRef = { idx: parseInt(match[1]), path: match[2] };
181-
// TODO: handle path.join of two absolute paths
182184
libRef.adjustedPath = path.join(projDir, libRef.path);
183-
thiz.parseProjectProrperies(libRef.adjustedPath, "###");
185+
refs.push(libRef);
186+
maxIdx = Math.max(maxIdx, libRef.idx);
184187
}
185188
});
189+
190+
var relLibDir = path.relative(projDir, libraryPath).split("\\").join("/");
191+
192+
var libRefExists = _.filter(refs, r => path.normalize(r.path) == path.normalize(relLibDir)).length > 0;
193+
194+
if (!libRefExists) {
195+
var projRef = util.format("\nandroid.library.reference.%d=%s", maxIdx + 1, relLibDir);
196+
fs.appendFileSync(projProp, projRef, { encoding: "utf-8" });
197+
}
186198
}
187199

188200
public addLibrary(platformData: IPlatformData, libraryPath: string): IFuture<void> {
@@ -193,7 +205,9 @@ class AndroidProjectService implements IPlatformProjectService {
193205

194206
this.parseProjectProrperies(libraryPath, targetPath);
195207

196-
this.updateProjectReferences(projDir, libraryPath);
208+
var targetLibPath = path.join(targetPath, path.basename(libraryPath));
209+
210+
this.updateProjectReferences(platformData.projectRoot, targetLibPath);
197211

198212
this.$errors.fail("Implement me!");
199213
return Future.fromResult();

0 commit comments

Comments
 (0)