Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2014 The Android Open Source Project
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.android.builder.sdk;
 
 import static com.android.SdkConstants.FN_AAPT;
 import static com.android.SdkConstants.FN_AIDL;
 import static com.android.SdkConstants.FN_BCC_COMPAT;
 import static com.android.SdkConstants.FN_RENDERSCRIPT;
 import static com.android.SdkConstants.FN_ZIPALIGN;
 
 
 import java.io.File;

Singleton-based implementation of SdkLoader for a platform-based SDK. Platform-based SDK are in the Android source tree in AOSP, using a different folder layout for all the files.
 
 public class PlatformLoader implements SdkLoader {
 
     private static PlatformLoader sLoader;
 
     @NonNull
     private final File mTreeLocation;
 
     private File mHostToolsFolder;
     private SdkInfo mSdkInfo;
     @NonNull
     private final ImmutableList<FilemRepositories;
 
     public static synchronized SdkLoader getLoader(
             @NonNull File treeLocation) {
         if ( != null && !treeLocation.equals(.)) {
             throw new IllegalStateException("Already created an SDK Loader with different SDK Path");
         }
 
         return  = new PlatformLoader(treeLocation);
     }
 
     public static synchronized void unload() {
          = null;
     }
 
     @NonNull
     @Override
     public TargetInfo getTargetInfo(@NonNull String targetHash,
             @NonNull FullRevision buildToolRevision, @NonNull ILogger logger) {
         init(logger);
 
         IAndroidTarget androidTarget = new FakeAndroidTarget(.getPath(), targetHash);
 
         File hostTools = getHostToolsFolder();
 
         BuildToolInfo buildToolInfo = new BuildToolInfo(
                 buildToolRevision,
                 ,
                 new File(hostTools),
                 new File(hostTools),
                 new File("prebuilts/sdk/tools/dx"),
                 new File("prebuilts/sdk/tools/lib/dx.jar"),
                 new File(hostTools),
                 new File("prebuilts/sdk/renderscript/include"),
                 new File("prebuilts/sdk/renderscript/clang-include"),
                 new File(hostTools),
                 new File(hostTools"arm-linux-androideabi-ld"),
                 new File(hostTools"i686-linux-android-ld"),
                 new File(hostTools"mipsel-linux-android-ld"),
                 new File(hostTools));
 
         return new TargetInfo(androidTargetbuildToolInfo);
     }
 
     @NonNull
     @Override
     public SdkInfo getSdkInfo(@NonNull ILogger logger) {
         init(logger);
        return ;
    }
    @Override
    @NonNull
    public ImmutableList<FilegetRepositories() {
        return ;
    }
    private PlatformLoader(@NonNull File treeLocation) {
         = treeLocation;
         = ImmutableList.of(new File( + "/prebuilts/sdk/m2repository"));
    }
    private synchronized void init(@NonNull ILogger logger) {
        if ( == null) {
            String host;
            if (. == .) {
                host = "darwin-x86";
            } else if (. == .) {
                host = "linux";
            } else {
                throw new IllegalStateException(
                        "Windows is not supported for platform development");
            }
             = new SdkInfo(
                    new File("out/host/" + host + "/framework/annotations.jar"),
                    new File("out/host/" + host + "/bin/adb"));
        }
    }
    @NonNull
    private synchronized File getHostToolsFolder() {
        if ( == null) {
            File tools = new File("prebuilts/sdk/tools");
            if (. == .) {
                 = new File(tools"darwin");
            } else if (. == .) {
                 = new File(tools"linux");
            } else {
                throw new IllegalStateException(
                        "Windows is not supported for platform development");
            }
            if (!.isDirectory()) {
                throw new IllegalStateException("Host tools folder missing: " +
                        .getAbsolutePath());
            }
        }
        return ;
    }
New to GrepCode? Check out our FAQ X